0

webpack当我在命令行上编译我的应用程序时,它编译得很好。我的test-unit脚本工作正常,但我的test-functional脚本失败:

 WEBPACK  Failed to compile with 2 error(s)

Error in ./node_modules/union/lib/core.js

  Module not found: 'spdy' in '/Users/ast70/projects/noteapp/node_modules/union/lib'

Error in ./node_modules/ecstatic/lib/ecstatic.js

  Module parse failed: Unexpected character '#' (1:0)
  You may need an appropriate loader to handle this file type.
  | #! /usr/bin/env node
  |
  | var path = require('path'),

包.json:

{
  "name": "noteapp",
  "version": "1.0.0",
  "description": "<obfuscated>",
  "main": "index.js",
  "scripts": {
    "lint": "./node_modules/.bin/eslint src test --cache",
    "start": "./node_modules/.bin/http-server",
    "test": "npm run test-unit; npm run test-functional",
    "test-unit": "./node_modules/.bin/mocha-webpack --interactive false $(find ./test/unit -name \"*.js\") -r chai/register-expect",
    "test-functional": "./node_modules/.bin/mocha-webpack --interactive false --webpack-config webpack.config.test-functional.js $(find ./test/functional -name \"*.js\") -r chai/register-expect --timeout 10000 || true"
  },
  "author": "<obfuscated>",
  "license": "ISC",
  "devDependencies": {
    "chai": "^4.1.2",
    "eslint": "^4.10.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.4.0",
    "http-server": "^0.10.0",
    "mocha": "^4.0.1",
    "mocha-webpack": "^2.0.0-alpha.0",
    "puppeteer": "^1.0.0",
    "sinon": "^4.1.3",
    "webpack-cli": "^2.1.3"
  },
  "dependencies": {
    "webpack": "^4.8.3"
  }
}

webpack.config:

module.exports = {
  entry: './src/word-list-controller.js',
  output: {
    filename: 'bundle.js'
  },
  mode: 'development'
};

webpack.config.test-functional.js:

const config = require('./webpack.config');

config.target = 'node';
module.exports = config;

我想使用的原因mocha-webpack是我不必webpack在运行测试之前手动编译。据称,mocha-webpack在不保存 a 的情况下也可以进行编译bundle.js,这很方便。

4

1 回答 1

0

我通过以下方式推进了我的错误:

  • npm install shebang-loader --save-dev
  • 添加到我的webpack.config.js

    模块:{规则:[{测试:/node_modules/ecstatic/lib/ecstatic.js/,加载器:['shebang-loader']}]}

于 2018-06-29T13:42:13.777 回答