question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

  1. Install nodejs >= 12.7.0 and @nuxtjs/composition-api@latest
  2. Launch node
  3. run require('@nuxtjs/composition-api/package.json')
  4. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
resesshcommented, Nov 18, 2020

That release solved my problem. Thank you!! ❤️

1reaction
danielroecommented, Nov 17, 2020

Let me know if that doesn’t solve your issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found