Once you switch your package.json to type: module, usage of the this package breaks, including utils such as babel-node.
Lets say your .babelrc.cjs looks like this:
module.exports = {
presets: [
[
"@babel/preset-env",
{
useBuiltIns: "usage",
corejs: {
version: 3,
proposals: true
},
targets: {
node: "14"
}
}
]
],
plugins: [
[
"module-resolver",
{
alias: {
src: "./src"
},
extensions: [".js"]
}
]
]
}
If you have a file like src/nested/very/deep.js and you want to load it in another file like src/nested-elsewhere/also/very/deep.js
$ babel-node src/nested-elsewhere/also/very/deep.js
results in:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'src' imported from /Users/myuser/Code/myproject/src/nested-elsewhere/also/very/deep.js
To reaffirm, this only happens once switching to ESM modules.
Once you switch your
package.jsontotype: module, usage of the this package breaks, including utils such asbabel-node.Lets say your
.babelrc.cjslooks like this:If you have a file like
src/nested/very/deep.jsand you want to load it in another file likesrc/nested-elsewhere/also/very/deep.jsresults in:
To reaffirm, this only happens once switching to ESM modules.