fix: Requiring `package.json` causes an error
See original GitHub issue🐛 The bug
Requiring @nuxtjs/composition-api/package.json
causes an error.
🛠️ To reproduce Steps to reproduce the behavior:
- Install
nodejs >= 12.7.0
and@nuxtjs/composition-api@latest
- Launch
node
- run
require('@nuxtjs/composition-api/package.json')
- See error
$ node
Welcome to Node.js v12.18.0.
Type ".help" for more information.
> require('@nuxtjs/composition-api/package.json')
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/resessh/src/github.com/resessh/repro-error/node_modules/@nuxtjs/composition-api/package.json
at applyExports (internal/modules/cjs/loader.js:491:9)
at resolveExports (internal/modules/cjs/loader.js:507:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:635:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:953:27)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at repl:1:1
at Script.runInThisContext (vm.js:120:20)
at REPLServer.defaultEval (repl.js:433:29) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
>
🌈 Expected behaviour No error
ℹ️ Additional context https://github.com/nodejs/node/issues/33460 is relevant discussion over this issue. This behavior is very surprising and the workaround is to add package.json to exports.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
ERR_REQUIRE_ESM and Package.json error on Next.js. after ...
This error is fixed when removing "type": "module" from package.json . Support for using ESM-only node_modules is still fine. The reason ...
Read more >package.json - npm Docs
Trying to install another plugin with a conflicting requirement may cause an error if the tree cannot be resolved correctly. For this reason,...
Read more >Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The easiest way to solve the error if using TypeScript is to downgrade the version of the package to one that is built...
Read more >Error Codes | Yarn - Package Manager
The author of packageA can fix this problem by adding a peer dependency on packagePeer . If relevant, they can use optional peer...
Read more >15 Common Error Codes in Node.js and How to Fix Them
To fix this error, you either need to create the expected directory structure or change the path so that the script looks in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That release solved my problem. Thank you!! ❤️
Let me know if that doesn’t solve your issue.