[Babel7] Does not resolve module for monorepo with babel-node
See original GitHub issueHi there,
I have a monorepo designed like this:
- packages
-- package-1
-- package-2
babel.config.js
In packages/package-2
I have a script defined in package.json
like this:
"dev": "babel-node --config-file ../../babel.config.js ./index.js",
The babel config for module-resolver is :
const plugins = [
[
"module-resolver",
{
cwd: "packagejson",
root: "./",
alias: {
"@package1": "./packages/package-1"
}
}
]
];
The babel config is loaded, but can’t resolve the module './packages/package-1'
:
Error: Cannot find module './packages/package-1'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> ([...]/packages/package-2/index.js:1:1)
at Module._compile (module.js:653:30)
at Module._compile ([...]/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (module.js:664:10)
at Object.newLoader [as .js] ([...]/node_modules/pirates/lib/index.js:88:7)
at Module.load (module.js:566:32)
Thanks a lot !
EDIT: workaround for me : using yarn workspaces https://yarnpkg.com/lang/en/docs/workspaces/#toc-how-to-use-it
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:16
Top Results From Across the Web
Babel preset not loading on monorepo project - Stack Overflow
Your Babel dependencies should be installed at the root package.json (since they will be shared across all packages).
Read more >Upgrade to Babel 7
The most important change is finally switching all packages to scoped packages (the folder names in the monorepo are not changed but the...
Read more >How to transpile node_modules with babel and webpack in a ...
In this case though, we are not transpiling between Javascript and a ... for the following caveat: It does not work when used...
Read more >Babel 7 + TypeScript - Artsy Engineering
One of the first things Babel 7 users will notice is the package ecosystem now exists as a monorepo and all NPM modules...
Read more >Turning a Node.js Monolith into a Monorepo without ... - InfoQ
the production build fails to run, because of Cannot find module errors;; and the import path to common-utils is more verbose than necessary....
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’s because babel does not build anything outside the current
cwd
. You’d need to override the ignore option to only include node_modules. This is how I do this, albeit with babel/register:@snaerth
I had the same problem as you. I solved it by creating a specific babel.config.js for each package and extending it to the root babel.config.js.
For each babel.config, I have this configuration: