I've been struggling to automate tests for my repository using mocha-webpack and Travis CI. The local machine runs the tests smoothly, but Travis CI hasn't been able to complete them yet due to an unresolved error:
WEBPACK Failed to compile with 1 error(s)
Error in ./src/ts/myfile.ts
Module not found: 'jQuery' in '/home/travis/build/myname/myrepo/src/ts'
The error suggests that webpack is looking for the jQuery module within my files instead of node_modules (I assume it's being imported through webpack.ProvidePlugin as there are no direct imports in myfile.ts).
test script
mocha-webpack --webpack-config webpack.config.js --require jsdom-global/register
dependencies
"jquery": "^3.2.1"
dev dependencies
"@types/chai": "^4.0.4"
"@types/jquery": "3.2.0"
"@types/mocha": "^2.2.42"
"chai": "^4.1.1"
"css-loader": "^0.28.5"
"jsdom": "^11.2.0",
"jsdom-global": "^3.0.2"
"mocha": "^3.5.0"
"mocha-typescript": "^1.1.7"
"mocha-webpack": "^1.0.0-rc.1"
"sass-loader": "^6.0.6"
"ts-loader": "^2.3.3"
"typescript": "^2.4.2"
"webpack": "^3.5.5"
webpack.config.js
const webpack = require("webpack");
module.exports = {
target: "node",
externals: ["jquery", "moment"],
resolve: {
extensions: [".ts", ".js"]
},
module: {
loaders: [
{ test: /\.ts$/, loader: "ts-loader" },
{ test: /\.scss$/, loaders: ['css-loader/locals?modules', 'sass-loader'] }
]
},
plugins: [
new webpack.ProvidePlugin({
$: "jQuery",
jQuery: "jQuery"
})
]
}
travis
language: node_js
node_js:
- "node"
cache:
directories:
- "node_modules"
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"lib": ["es2016", "dom"],
"typeRoots": [
"node_modules/@types"
],
"experimentalDecorators": true // For the decorators in Mocha tests.
},
"compileOnSave": true,
"include": [
"src/**/*",
"test/*"
]
}