无法在我的Gulp + Angular项目上执行npm install

时间:2017-03-25 06:47:05

标签: node.js angular gulp

我创建了一个项目,其中我使用了Angular2的gulp。但是在执行npm install时会出现以下错误跟踪:

> typings install && gulp check.versions && npm prune


`-- xhr2

[12:06:55] Requiring external module ts-node/register
----------------------------------
? Unable to compile TypeScript

gulpfile.ts (1,23): Cannot find module 'gulp'. (2307)
tools\config.ts (1,28): Cannot find module 'fs'. (2307)
tools\config.ts (2,20): Cannot find module 'yargs'. (2307)
tools\config.ts (3,31): Cannot find module 'path'. (2307)
tools\config.ts (4,24): Cannot find module 'chalk'. (2307)
tools\config.ts (15,52): Cannot find name '__dirname'. (2304)
tools\config.ts (64,3): Cannot find name 'process'. (2304)
tools\config.ts (221,50): Cannot find name 'require'. (2304)
tools\configW.ts (1,28): Cannot find module 'fs'. (2307)
tools\configW.ts (2,20): Cannot find module 'yargs'. (2307)
tools\configW.ts (3,31): Cannot find module 'path'. (2307)
tools\configW.ts (4,24): Cannot find module 'chalk'. (2307)
tools\configW.ts (5,23): Cannot find module 'gulp-util'. (2307)
tools\configW.ts (17,52): Cannot find name '__dirname'. (2304)
tools\configW.ts (36,52): Cannot find name '__dirname'. (2304)
tools\configW.ts (72,3): Cannot find name 'process'. (2304)
tools\configW.ts (236,50): Cannot find name 'require'. (2304)
tools\manual_typings\merge-stream.d.ts (2,36): Cannot find namespace 'NodeJS'. (2503)
tools\manual_typings\merge-stream.d.ts (3,33): Cannot find namespace 'NodeJS'. (2503)
tools\manual_typings\merge-stream.d.ts (4,17): Cannot find namespace 'NodeJS'. (2503)
tools\manual_typings\systemjs-builder.d.ts (4,60): Cannot find name 'Promise'. (2304)
tools\manual_typings\systemjs-builder.d.ts (5,65): Cannot find name 'Promise'. (2304)
tools\utils.ts (9,17): Cannot find name 'require'. (2304)
tools\utils\code_change_tools.ts (2,30): Cannot find module 'browser-sync'. (2307)
tools\utils\code_change_tools.ts (10,18): Cannot find name 'require'. (2304)
tools\utils\server.ts (1,26): Cannot find module 'express'. (2307)
tools\utils\server.ts (3,30): Cannot find module 'serve-static'. (2307)
tools\utils\server.ts (5,23): Cannot find module 'path'. (2307)
tools\utils\server.ts (22,25): Cannot find name 'process'. (2304)
tools\utils\server.ts (35,25): Cannot find name 'process'. (2304)
tools\utils\tasks_tools.ts (1,23): Cannot find module 'gulp'. (2307)
tools\utils\tasks_tools.ts (2,23): Cannot find module 'gulp-util'. (2307)
tools\utils\tasks_tools.ts (3,24): Cannot find module 'chalk'. (2307)
tools\utils\tasks_tools.ts (4,34): Cannot find module 'gulp-load-plugins'. (2307)
tools\utils\tasks_tools.ts (5,31): Cannot find module 'run-sequence'. (2307)
tools\utils\tasks_tools.ts (6,50): Cannot find module 'fs'. (2307)
tools\utils\tasks_tools.ts (7,20): Cannot find module 'path'. (2307)
tools\utils\tasks_tools.ts (19,10): Cannot find name 'require'. (2304)
tools\utils\template_injectables.ts (4,20): Cannot find module 'path'. (2307)
----------------------------------
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN enoent ENOENT: no such file or directory, open 'C:\...\tool-design\frontend\node_modules\es5-ext\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\...\tool-design\frontend\node_modules\escodegen\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\..\tool-design\frontend\node_modules\exit\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\..\tool-design\frontend\node_modules\escodegen\node_modules\source-map\package.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wi-automation-frontend@0.0.1 postinstall: `typings install && gulp check.versions && npm prune`
npm ERR! Exit status 1

我拥有的gulp文件是:

import * as gulp from 'gulp';
import {runSequence, task} from './tools/utils';

// --------------
// Clean (override).
gulp.task('clean', done => task('clean', 'all')(done));
gulp.task('clean.dev', done => task('clean', 'dev')(done));
gulp.task('clean.prod', done => task('clean', 'prod')(done));
gulp.task('clean.prodW', done => task('clean', 'prodW')(done));
gulp.task('check.versions', () => task('check.versions'));
gulp.task('build.docs', () => task('build.docs'));
gulp.task('serve.docs', () => task('serve.docs'));
gulp.task('serve.coverage', task('serve.coverage'));

// --------------
// Build dev.
gulp.task('build.dev', done =>
  runSequence('clean.dev',
    'tslint',
    'build.assets.dev',
    'build.js.dev',
    'build.index.dev',
    done));

// --------------
// Build dev watch.
gulp.task('build.dev.watch', done =>
  runSequence('build.dev',
    'watch.dev',
    done));

// --------------
// Build e2e.
gulp.task('build.e2e', done =>
  runSequence('clean.dev',
    'tslint',
    'build.assets.dev',
    'build.js.e2e',
    'build.index.dev',
    done));

// --------------
// Build prod.
gulp.task('build.prod', done =>
  runSequence('clean.prod',
    // 'tslint',
    'build.assets.prod',
    'build.html_css.prod',
    'build.js.prod',
    'build.bundles',
    'build.bundles.app',
    'build.index.prod',
    done));

// Move.
gulp.task('build.prod.move', done =>
  runSequence('build.prod',
    'build.move.prod',
    done));
// --------------
// Build test.
gulp.task('build.test', done =>
  runSequence('clean.dev',
    'tslint',
    'build.assets.dev',
    'build.js.test',
    'build.index.dev',
    done));

// --------------
// Build test watch.
gulp.task('build.test.watch', done =>
  runSequence('build.test',
    'watch.test',
    done));

// --------------
// Docs
// Disabled until https://github.com/sebastian-lenz/typedoc/issues/162 gets resolved
gulp.task('docs', done =>
  runSequence('build.docs',
    'serve.docs',
    done));

// --------------
// Serve dev
gulp.task('serve.dev', done =>
  runSequence('build.dev',
    'server.start',
    'watch.serve',
    done));

// --------------
// Serve e2e
gulp.task('serve.e2e', done =>
  runSequence('build.e2e',
    'server.start',
    'watch.serve',
    done));

// --------------
// Serve prod
gulp.task('serve.prod', done =>
  runSequence('build.prod',
    'server.start',
    'watch.serve',
    done));

// --------------
// Test.
gulp.task('test', done =>
  runSequence('build.test',
    'karma.start',
    done));

// Build prod.
gulp.task('build.prodW', done =>
  runSequence('clean.prodW',
    'tslint',
    'build.assets.prodW',
    'build.html_css.prodW',
    'build.js.prodW',
    'build.bundlesW',
    'build.bundles.appW',
    // 'build.index.prodW',
    'build.index.inject.asset.prodW',
    done));

// Move.
gulp.task('build.moveW.prodW', done =>
  runSequence('build.prodW',
    'build.move.prodW',
    done));


// Serve prod
gulp.task('serve.prodW', done =>
  runSequence('build.moveW.prodW',
    'server.start',
    'watch.serve',
    done));

请帮我纠正这个问题。我已尝试全局删除gulp并重新安装gulp,typings和ts-node。

1 个答案:

答案 0 :(得分:0)

只是几个想法:

  1. 您是否正在从项目根目录进行npm安装?如果没有去项目根并从那里安装。
  2. 您的模块是全局安装还是本地安装? (连接到#1)
  3. 您检查过package.json了吗?这些条目是否符合您应该安装的内容?
  4. 您对目录有读/写权限吗? (有点关键)。