【问题标题】:mocha-webpack failing to compile - unexpected character '#'mocha-webpack 无法编译 - 意外字符“#”
【发布时间】:2018-05-18 15:39:46
【问题描述】:

当我在命令行上使用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,这很方便。

【问题讨论】:

    标签: webpack mocha.js mocha-webpack


    【解决方案1】:

    处理了我的错误:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-28
      • 2022-07-05
      • 2020-11-18
      • 1970-01-01
      • 2016-06-04
      • 2023-03-26
      • 1970-01-01
      • 2016-01-08
      相关资源
      最近更新 更多