mocha-webpack failing to compile - unexpected character '#'

386 Views Asked by At

When I compile my app with webpack on the command line it compiles fine. My test-unit script works fine but my test-functional script fails with:

 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;

The reason I want to use mocha-webpack is so I don't have to manually compile with webpack before I run my tests. Allegedly, mocha-webpack does the compiling without saving a bundle.js, too, which is handy.

1

There are 1 best solutions below

0
On

I progressed my error by:

  • npm install shebang-loader --save-dev
  • adding to my webpack.config.js:

    module: { rules: [ { test: /node_modules/ecstatic/lib/ecstatic.js/, loaders: ['shebang-loader'] } ] }