Friday, 20 November 2020

React 16.14.0: Error was not caught ReferenceError: exports is not defined

I'm the author of next-translate library, and I'm working on an experimental version to which I get an error with React 16.14.0 and I don't understand why it happens. Upgrading React to version 17 then it works fine, but I don't want to force everyone who uses the new version of my library to migrate their React version.

I've created a reproducible error example: https://github.com/aralroca/next-translate-error-reproduction

In order to reproduce this issue:

  • Clone this repo
  • Run yarn && yarn dev
  • Open localhost:3000
  • Open devtools

Error was not caught ReferenceError: exports is not defined

And the prerelease code of my lib is here:

tsconfig.json

{
  "compilerOptions": {
    "strict": false,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "removeComments": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "declaration": true,
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "./lib/esm"
  },
  "include": ["./src"]
}

tsconfig-cjs.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "CommonJS",
    "outDir": "./lib/cjs",
    "declaration": false
  }
}

And this is the package code:

If anyone knows where this error came from and can help me I would be very grateful! I've been trying to solve it for several days but I'm a little lost because I don't know why it's happening... Thanks!

Note: Looks that it only happens in development, doing yarn build && yarn start works fine.



from React 16.14.0: Error was not caught ReferenceError: exports is not defined

No comments:

Post a Comment