Composition-api: fix: Requiring `package.json` causes an error

Created on 17 Nov 2020  ·  5Comments  ·  Source: nuxt-community/composition-api

🐛 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.

Most helpful comment

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

All 5 comments

@resessh Happy to add. Out of curiosity, what's your use-case?

@danielroe I'm sorry for lack of my use-case. This repo reproduce the problem I'm having trouble with.

There seems to be two problems. One is 'requiring package.json fails', and the other is 'no exports fields for nodejs' .

@danielroe I created a PR and it really solves this problem. Could you check it?
https://github.com/nuxt-community/composition-api/pull/296

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

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

Was this page helpful?
0 / 5 - 0 ratings