Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Travis CI,Mocha测试,网页包编译错误:未找到模块:';jQuery';_Jquery_Typescript_Webpack_Mocha.js_Travis Ci - Fatal编程技术网

Travis CI,Mocha测试,网页包编译错误:未找到模块:';jQuery';

Travis CI,Mocha测试,网页包编译错误:未找到模块:';jQuery';,jquery,typescript,webpack,mocha.js,travis-ci,Jquery,Typescript,Webpack,Mocha.js,Travis Ci,我一直在尝试使用mocha webpack和Travis CI为我的存储库设置自动化测试。我的测试在本地机器上运行良好,但它们还不能通过Travis CI完成。我无法找出最后一个错误: 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' 根据错误消息,webpac

我一直在尝试使用mocha webpack和Travis CI为我的存储库设置自动化测试。我的测试在本地机器上运行良好,但它们还不能通过Travis CI完成。我无法找出最后一个错误:

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'
根据错误消息,webpack似乎正在尝试解析我文件中的jQuery模块(我假设导入是通过我的webpack.ProvidePlugin调用添加的,因为myfile.ts中没有jQuery导入),而不是在node_模块中查找

测试脚本

依赖关系

开发依赖项

webpack.config.js

特拉维斯

tsconfig.json


我通过一些实验找到了答案

My webpack.config.js已将jquery定义为外部:

externals: ["jquery", "moment"]
这导致模块从环境中删除。然而,我似乎能够通过ProvidePlugin在我的本地机器上运行它:

new webpack.ProvidePlugin({
    $: "jQuery",
    jQuery: "jQuery"
})
注意jQuery中的大写字母Q。对于我的本地环境,jQuery(由于没有在externals行中定义,所以没有被删除)被定义为jQuery模块,但是在travis ci上,却找不到它。我仍然不知道为什么“jQuery”一开始对我有效

通过从配置中删除externals行,并将jQuery更改为全小写,它解决了我的问题:

new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery"
})
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"
    })
  ]
}
language: node_js
node_js:
  - "node"

cache:
  directories:
    - "node_modules"
{
    "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/*"
    ]
}
externals: ["jquery", "moment"]
new webpack.ProvidePlugin({
    $: "jQuery",
    jQuery: "jQuery"
})
new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery"
})