Angular-Fullstack Requiring external module babel-register

喜夏-厌秋 提交于 2019-12-14 02:35:44

问题


I am getting this error when use gulp serve from a angular-fullstack project generator. Please, how can I solve this issue? The dependencie was set in package.json properly.

[18:03:54] Requiring external module babel-register
/home/gcfabri/Workspace/sportfitness/gulpfile.babel.js:4
import _ from 'lodash';
^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at loader (/home/gcfabri/node_modules/babel-register/lib/node.js:134:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/gcfabri/node_modules/babel-register/lib/node.js:144:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Liftoff.handleArguments (/home/gcfabri/.npm-global/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/home/gcfabri/.npm-global/lib/node_modules/gulp/node_modules/liftoff/index.js:192:16)

回答1:


It sounds like you need to run npm install --save babel-require. You can read more about it here.

Edit: Just to explain a bit better, the purpose of babel-require is to compile required packages with babel on the fly. In this case I'm assuming it's meant to be compiling ES6 javascript syntax back to ES5 syntax, because it's failing on the newer ES6 import syntax.

I'm not sure how babel ended up in your gulp pipeline there, but it's explicitly being required by something in /home/gcfabri/Workspace/sportfitness/gulpfile.babel.js. I wouldn't recommend removing it, but just so you have an idea of what's happening.

I hope installing that dependancy helps.



来源:https://stackoverflow.com/questions/35349078/angular-fullstack-requiring-external-module-babel-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!