Plugins section from .babelrc file:
"plugins": [
"inline-import",
"transform-object-entries",
"transform-object-rest-spread",
["module-resolver", {
"root": "./src"
}]
]
Resolving works fine with babel src command creating a final build.
But when I'm trying to debug my app locally using babel-node w/o transpiling, it doesn't want to resolve root path saying: Cannot find module 'utils/api'
Folders structure:
.babelrc
package.json
src/utils/api.js
I'm not sure if I understand this bit:
But when I'm trying to debug my app locally using babel-node w/o transpiling, it doesn't want to resolve root path saying:
Cannot find module 'utils/api'
If you don't transpile, then the plugin is not applied.
I thought it applies all plugins from .babelrc automatically.
Is there any option to run a script using babel-node or via node parameter -r babel-register and get module resolving on-the-fly?
That's strange - could you publish a small reproduction repo on GitHub?
Sure, here it is: https://github.com/bashjs/babel-example
Thanks, I'll take a look at it later this day.
I was unable to reproduce. I tried doing it both on Windows and Ubuntu and it just worked. Maybe you need to clear Babel cache or something? Here's a dump from my console when running on Ubuntu:
โ ~ g clone https://github.com/bashjs/babel-example.git
Cloning into 'babel-example'...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 26 (delta 7), reused 23 (delta 6), pack-reused 0
Unpacking objects: 100% (26/26), done.
Checking connectivity... done.
โ ~ cd babel-example
โ babel-example git:(master) npm i
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 182 packages in 3.837s
โ babel-example git:(master) โ npm run dev
> [email protected] dev /home/fatfisz/babel-example
> node -r babel-register ./src/script.js
UKRAINE
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Update available 5.6.0 โ 6.2.0 โ
โ Run npm i -g npm to update โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ babel-example git:(master) โ gco working
M package-lock.json
Branch working set up to track remote branch working from origin.
Switched to a new branch 'working'
โ babel-example git:(working) โ npm i
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
up to date in 1.787s
โ babel-example git:(working) โ npm run dev
> [email protected] dev /home/fatfisz/babel-example
> node -r babel-register ./src/script.js
UKRAINE
โ babel-example git:(working) โ
Btw. I also tried removing "root" from module-resolver config and then it resulted in an error (just a sanity check to see if module-resolver is working as expected).
Thank you for your response! I'll double check.
UPD It is magically works fine now. Thank you again for your time!
It somebody will encounter this issue: Try to clean babel cache
UPD2 Actually, root of my issue was Working directory parameter in Node.js Run/Debug script section in WebStorm.
It should be that folder, where your .babelrc file lies (usually root of your project)