首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mocha-webpack编译失败-意外字符'#‘

mocha-webpack编译失败-意外字符'#‘
EN

Stack Overflow用户
提问于 2018-05-18 23:39:47
回答 1查看 301关注 0票数 0

当我在命令行上使用webpack编译我的应用程序时,它编译得很好。我的test-unit脚本工作得很好,但是我的test-functional脚本失败了,出现以下错误:

代码语言:javascript
复制
 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:

代码语言:javascript
复制
{
  "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:

代码语言:javascript
复制
module.exports = {
  entry: './src/word-list-controller.js',
  output: {
    filename: 'bundle.js'
  },
  mode: 'development'
};

webpack.config.test-functional.js:

代码语言:javascript
复制
const config = require('./webpack.config');

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

我想使用mocha-webpack的原因是,这样我就不必在运行测试之前手动使用webpack编译。据说,mocha-webpack不需要保存bundle.js就可以进行编译,这很方便。

EN

回答 1

Stack Overflow用户

发布于 2018-06-29 21:42:14

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

指向我的webpack.config.js

  • npm install shebang-loader --save-dev
  • adding:

模块:{规则:[{ test: /node_modules/ecstatic/lib/ecstatic.js/,loaders:'shebang-loader‘}] }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50414886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档