mocha-webpack无法编译 - 意外字符'#'

时间:2018-05-18 15:39:47

标签: webpack mocha mocha-webpack

当我在命令行上使用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'),

的package.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在不保存bundle.js的情况下进行编译,这很方便。

1 个答案:

答案 0 :(得分:0)

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

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

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