【发布时间】:2017-03-30 09:36:09
【问题描述】:
我有一个应用程序,我正在尝试执行npm install && 然后是gulp build。除非我给出 NODE_ENV=production,否则它工作正常,因为 npm 不会安装 devDependencies 中列出的模块。
以下是一些sn-ps。
"devDependencies": {
"aliasify": "^2.0.0",
"babel": "^6.5.2",
"babel-plugin-__coverage__": "^11.0.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babelify": "^7.3.0"
}
错误
[13:10:13] Failed to load external module babel-register
[13:10:13] Failed to load external module babel-core/register
[13:10:13] Failed to load external module babel/register
/path/to/repository/gulpfile.babel.js:1
(function (exports, require, module, __filename, __dirname) { import gulp from 'gulp';
^^^^^^
SyntaxError: Unexpected reserved word
由于我正在尝试构建用于生产的应用程序,因此未安装 babel 及其依赖项。我什至无法开始构建。
请提出解决方案。
【问题讨论】:
-
我认为
import gulp from 'gulp';必须在文件/path/to/repository/gulpfile.babel.js的顶部而不是在功能块中 -
它不在功能块中。我的 gulpfile.babel.js 看起来像这样。
import gulp from 'gulp'; import runSequence from 'run-sequence'; import browserSync from 'browser-sync'; import nodemon from 'gulp-nodemon'; import gulpLoadPlugin from 'gulp-load-plugins'; import './gulp/common'; import './gulp/script'; import './gulp/style'; import './gulp/test'; const gulpSequence = runSequence.use(gulp); const $ = gulpLoadPlugin(); gulp.task('build', (callback) => { gulpSequence('clean', 'preprocess', 'styles', 'scripts', 'resources', 'tmp-del', callback); });