简体   繁体   English

Babel-node无法在node_modules下编译js,如何解决?

[英]Babel-node cannot compile js under node_modules, how to resolve it?

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: test1.js / test2.js:

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

.babelrc: .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情况下测试

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

Result: 结果:

...{a: 123}
^^^

SyntaxError: Unexpected token ...

似乎不再使用/查找预设,请尝试将.babelrc复制到node_modules。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM