I'm trying to run gulp
to build my app like Rob Dodson explains here
在命令行中,如果我运行:
npm run build
我收到以下错误:
[20:50:55] Using gulpfile ~/path/to/gulpfile.js [20:50:55] Starting 'default'... Deleting build/ directory... [20:50:56] The following tasks did not complete: default [20:50:56] Did you forget to signal async completion?
似乎有一些任务描述为" 信号异步完成?"这是什么意思?我该怎么做?
但是,如果我在命令行运行以下命令:
gulp
我收到如下错误消息:
[23:40:57] Using gulpfile ~/path/to/gulpfile.js /usr/local/lib/node_modules/gulp/bin/gulp.js:129 gulpInst.start.apply(gulpInst, toRun); ^ TypeError: Cannot read property 'apply' of undefined at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:19 at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13) at Function.Module.runMain (module.js:443:11) at startup (node.js:139:18) at node.js:968:3
为什么会出现不同的错误消息?这是否暗示了导致错误的原因是什么?如果是这样,它是什么?我该怎么做才能解决它?
I just copied the files package.json, polymer.json and gulpfile.js from the sample code Rob supplied here。然后我运行了npm install
as this answer describes。
'use strict';
// Documentation on what goes into PolymerProject.
const path = require('path');
const gulp = require('gulp');
const mergeStream = require('merge-stream');
const del = require('del');
const polymerJsonPath = path.join(process.cwd(), 'polymer.json');
const polymerJSON = require(polymerJsonPath);
const polymer = require('polymer-build');
const polymerProject = new polymer.PolymerProject(polymerJSON);
const buildDirectory = 'build/bundled';
/**
* Waits for the given ReadableStream
*/
function waitFor(stream) {
return new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
});
}
function build() {
return new Promise((resolve, reject) => {
// Okay, so first thing we do is clear the build
console.log(`Deleting build/ directory...`);
del([buildDirectory])
.then(_ => {
// Okay, now lets get your source files
let sourcesStream = polymerProject.sources()
// Oh, well do you want to minify stuff? Go for it!
// Here's how splitHtml & gulpif work
.pipe(polymerProject.splitHtml())
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.css$/, cssSlam()))
.pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(polymerProject.rejoinHtml());
// Okay now lets do the same to your dependencies
let depsStream = polymerProject.dependencies()
.pipe(polymerProject.splitHtml())
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.css$/, cssSlam()))
.pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(polymerProject.rejoinHtml());
// Okay, now lets merge them into a single build stream.
let buildStream = mergeStream(sourcesStream, depsStream)
.once('data', () => {
console.log('Analyzing build dependencies...');
});
// If you want bundling, do some bundling! Explain why?
buildStream = buildStream.pipe(polymerProject.bundler);
// If you want to add prefetch links, do it! Explain why?
// buildStream = buildStream.pipe(new PrefetchTransform(polymerProject));
// Okay, time to pipe to the build directory
buildStream = buildStream.pipe(gulp.dest(buildDirectory));
// waitFor the buildStream to complete
return waitFor(buildStream);
})
.then(_ => {
// You did it!
console.log('Build complete!');
resolve();
});
});
}
gulp.task('default', build);
答案 0 :(得分:1)
原始错误与“备用错误”无关。
虽然build
task runs gulp
,npm run
在系统安装gulp
之前优先考虑本地安装的node_modules/.bin/gulp
(gulp
)。自己运行gulp
(没有npm run
)会调用全局安装的gulp
,如果它与您的项目不兼容,可能会导致错误(例如,Gulp 3二进制文件与Gulp 4 API)你的脚本,似乎是这种情况)。您可以安装Gulp 4,以便自己运行gulp
,或继续使用npm run build
。
要解决原始错误,我建议从Polycast's original source(如果您还没有)开始,以确定可能存在的差异。
如果您更喜欢坚持当前的曲目,我建议您做一些事情:
polymer-build
issue 88)。运行polymer build -v
(详细构建)可能会有所帮助。buildStream.on('error', (err) => console.log(err))
之后添加let buildStream = ...
,以防在该流中出现任何未解压缩的error
个事件。答案 1 :(得分:1)
我建议您使用新版本的PSK Custom Build:
https://github.com/PolymerElements/generator-polymer-init-custom-build/
已更新gulpfile.js
。
答案 2 :(得分:0)
问题是由错误的导入路径引起的。
路径错误<link rel="import" href="../../../bower_components/polymer/polymer.html">
正确的道路
<link rel="import" href="../../bower_components/polymer/polymer.html">
正如@ tony19所描述的那样,错误的导入路径导致了无声失败。
我通过追求@abdonrd建议的路径找到了这个。 I followed the instructions here as follows
首先,我复制了我的项目。然后按照下面描述的过程加载到my-app
目录中。
npm install -g polymer-cli
npm install -g generator-polymer-init-custom-build
mkdir my-app
cd my-app
polymer init custom-build
polymer build -v # the results of this command highlighted my error in red
错误显示了丢失文件的路径。我注意到它位于比应有的高一级,因为路径中缺少根目录my-app/
。然后我不得不使用搜索字符串polymer/polymer.html
手动搜索所有文件,直到我发现导入路径中的../
数量(本例中为3)与深入的文件夹数量不匹配导入文件的根目录(本例中为2)。
在我更正文件路径后,我再次运行:
polymer build -v # building the project again, correctly this time
polymer serve build/bundled # to test serve the build/bundled version