Angular Universal + Nunjucks导致node-gyp错误

时间:2018-12-03 18:01:00

标签: angular webpack nunjucks

在OS X 10.14.1上,当使用Nunjucks作为Angular Universal的模板引擎时,我收到:

ERROR in ./node_modules/node-gyp/lib/node-gyp.js
Module not found: Error: Can't resolve '../package' in '/Users/btaylor/work/angular-apps/lvs-ui/node_modules/node-gyp/lib'
 @ ./node_modules/node-gyp/lib/node-gyp.js 67:16-37
 @ ./node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js
 @ ./node_modules/fsevents/node_modules/node-pre-gyp/lib sync ^\.\/.*$
 @ ./node_modules/fsevents/node_modules/node-pre-gyp/lib/node-pre-gyp.js
 @ ./node_modules/fsevents/fsevents.js
 @ ./node_modules/chokidar/lib/fsevents-handler.js
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/nunjucks/src/node-loaders.js
 @ ./node_modules/nunjucks/src/loaders.js
 @ ./node_modules/nunjucks/index.js
 @ ./server.ts

在构建server.ts时。这是我的webpack.server.config.js文件:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: { server: './server.ts' },
  resolve: { extensions: ['.js', '.ts'] },
  target: 'node',
  mode: 'none',
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/node_modules/],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [{ test: /\.ts$/, loader: 'ts-loader' }]
  },
  plugins: [
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for 'WARNING Critical dependency: the request of a dependency is an expression'
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
};

此构建过程在Windows 10上运行良好。我尝试过:

通过nvm完全重新安装节点10、9和8。 遵循https://github.com/strongloop/fsevents/issues/229和其他无数文章上的建议。

似乎node-gyp无法从node-gyp / lib / node-gyp.js 67中的这一行导出package.json:

/**
 * Export the contents of the package.json.
 */

proto.package = require('../package')

注释上一行似乎并没有真正影响构建,但确实会引发其他一些警告。

任何人都知道为什么会发生这种情况以及我可以采取什么措施来解决它?

0 个答案:

没有答案