Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: (0 , _nanoevents.createNanoEvents) is not a function #45

Closed
karolis-sh opened this issue Apr 14, 2020 · 5 comments
Closed

TypeError: (0 , _nanoevents.createNanoEvents) is not a function #45

karolis-sh opened this issue Apr 14, 2020 · 5 comments

Comments

@karolis-sh
Copy link

Hi 👋

I'm trying use/test nanonevents in codesandbox (https://codesandbox.io/s/mutable-shape-8urc9?file=/src/index.js) and with create-react-app's jest, both environments don't work with the library out of the box.

As I understand some of the defaults don't work well with *.cjs file extension ("main": "index.cjs",). Maybe it's worth renaming the file to follow a more common extension?

FYI: Renaming index.cjs -> index.cjs.js and changing "main": "index.cjs", -> "main": "index.cjs.js", seems to fix the issue.

@ai
Copy link
Owner

ai commented Apr 14, 2020

@karolis-sh can you leave a comment at this pull request, that you need this fix anf to ask them to release the fix from merged pull request?

@ai
Copy link
Owner

ai commented Apr 14, 2020

Renaming index.cjs -> index.cjs.js

We can’t do it, because it will break Node.js native ESM support. In Node.js (in contract to Babel, which broke the spec) you must explicitly show that this file is ES module. In package.type: "module" we mark the whole project as a ESM project. So, without .cjs file extension, Node.js will try to load thus CJS file as ESM and will throw an error.

@karolis-sh
Copy link
Author

Thanks for explanation! I wasn't aware about the new *.cjs extension - good to know.

@ankon
Copy link

ankon commented Oct 16, 2020

From facebook/create-react-app#9814, but to help out here:

It is possible to apply the needed changes to an existing project, by using the fact that react-scripts test passes through arguments to jest, and jest uses the command-line-provided arguments as overrides:

In package.json, replace the invocation to react-scripts test with something like this:

{
  // ...
  "scripts": {
    // ...
    "test": "react-scripts test --transform '{\"^.+\\\\.(js|jsx|mjs|cjs|ts|tsx)$\":\"<rootDir>/node_modules/react-scripts/config/jest/babelTransform.js\", \"^.+\\\\.css$\": \"<rootDir>/node_modules/react-scripts/config/jest/cssTransform.js\", \"^(?!.*\\\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)\": \"<rootDir>/node_modules/react-scripts/config/jest/fileTransform.js\"}' --transformIgnorePatterns '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$' --transformIgnorePatterns '^.+\\.module\\.(css|sass|scss)$'",
    // ..
  },
  // ...
}

@ai
Copy link
Owner

ai commented Dec 1, 2020

The lastest CRA release fixed the problem

@ai ai closed this as completed Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants