0

I've struggled for this question for a long time, i've tried all possible solutions by google, but it still didn't work.
Here, i set an brief example to describe the problem. Assume we created the structure:

test
|  
|____ test1.js
|
|____ node_modules
|     |
|     |____ test2.js
|     |
|     |____ [babel modules...]
|  
|____ .babelrc
|  
|____ package.json

test1.js / test2.js:

console.log({
  ...{a: 123}
})

.babelrc:

{
  "presets": ["es2015", "stage-2"]
}

Test in normal situation

node_modules/.bin/babel-node test1.js

Result:

{ a: 123 }

Test in node_modules situation

node_modules/.bin/babel-node node_modules/test2.js

Result:

...{a: 123}
^^^

SyntaxError: Unexpected token ...
TerrySu
  • 158
  • 8

1 Answers1

0

Seems it is not using/finding the presets anymore, try copying .babelrc to node_modules.

Isidrok
  • 2,015
  • 10
  • 15
  • Yes or no. In the example case, it works, but in other situations,like: `babel-node node_modules/oneModule/main/index.js, it still doesn't work. However, i change the way by coping the files to compile to local to complete task. Anyway, thanks a lot. – TerrySu Sep 11 '17 at 10:54