Node: Errors from conditional exports after upgraded to Node 13.13

Created on 14 Apr 2020  路  6Comments  路  Source: nodejs/node

  • Version: Node.js 13.13
  • Platform: 19.4.0 Darwin Kernel Version 19.4.0
  • Subsystem: ES modules

What steps will reproduce the bug?

npm install @babel/compat-data
node -e "require('@babel/compat-data/corejs3-shipped-proposals')"

What is the expected behavior?

It should load the module as expected in Node.js 13.12

What do you see instead?

Error: Cannot find module '@babel/compat-data/corejs3-shipped-proposals'
Require stack:
- /tmp/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)
    at [eval]:1:9
    at Script.runInThisContext (vm.js:131:20)
    at Object.runInThisContext (vm.js:297:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1123:30)
    at evalScript (internal/process/execution.js:94:25)
    at internal/main/eval_string.js:23:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/tmp/[eval]' ]
}

Additional information

Caught by the Babel CI: https://travis-ci.com/github/babel/babel/jobs/319348116#L360

The regression was likely introduced in https://github.com/nodejs/node/pull/32351.

The file structure of @babel/compat-data can be simplified w.l.o.g as

package.json
corejs3-shipped-proposals.js
data/corejs3-shipped-proposals.json

and the package.json:

"exports": {
  "./corejs3-shipped-proposals": "./data/corejs3-shipped-proposals.json"
}

The corejs3-shipped-proposals.js is a proxy which delegates to "./data/corejs3-shipped-proposals.json" for Node.js < 13.3 support.

module.exports = require("./data/corejs3-shipped-proposals.json");

Most helpful comment

@guybedford Ahh thanks. It was release in 7.9.0.

For those babel users who are affected by this issue after upgrading to node.js 13.13/12.17, please upgrade @babel/preset-env to 7.9.0.

All 6 comments

/cc @guybedford

@JLHwung I created https://github.com/babel/babel/pull/11283 specifically to avoid Babel having this error. Was the above fix not patched and released already?

@guybedford Ahh thanks. It was release in 7.9.0.

For those babel users who are affected by this issue after upgrading to node.js 13.13/12.17, please upgrade @babel/preset-env to 7.9.0.

Great, I'm glad the early fix here could help!

I had this problem in building a React Native Bob library. I solved it using nvm install 13.12, which downgraded my node to 13.12.

This solution only applies if you use nvm to manage your Node versions (if you don't I recommend it!)

FYI, I noticed the same issue in 12.17.x. We have to switch to 12.6.x in Travis for now.

Was this page helpful?
0 / 5 - 0 ratings