找不到'jasmine_light.js'中的模块'./create_spy'

时间:2018-02-21 10:02:36

标签: webpack jestjs

我在这些配置中收到此错误:

  

在Resolver.resolveModule   (node_modules /开玩笑-解析/生成/ index.js:194:17)

node -v = v8.9.4

webpack.config.js

var webpack = require('webpack');


module.exports = {
  module: {
    loaders: [
      {exclude: ['node_modules'], loader: 'babel', test: /\.jsx?$/},
      {loader: 'style-loader!css-loader', test: /\.css$/},
      {loader: 'url-loader', test: /\.gif$/},
      {loader: 'file-loader', test: /\.(ttf|eot|svg)$/},
    ],
  },
  resolve: {
    extensions: ['', 'js', 'jsx'],
    modules: [
      'node_modules',
      'bower_components',
      'shared',
      '/shared/vendor/modules',
    ],
  },
};

包json:

{
  "name": "frontend",
  "jestWebpackResolver": {
    "silent": true,
    "webpackConfig": "./tests/webpack.config.js"
  },
  "private": true,
  "version": "3.0.0-alpha.1",
  "description": "Zaask FrontEnd",
  "main": "src/app/index.js",
  "scripts": {
    "clean": "rimraf dist/*",
    "copy": "copyfiles -f ./src/app/index.html ./dist && copyfiles -u 1 \"./src/assets/**\" ./dist",
    "dist": "npm run clean && npm run copy && webpack --progress --bail --env dist -p",
    "lint": "./node_modules/.bin/eslint ./src/app/",
    "serve:dev": "webpack-dev-server --env dev",
    "serve:dist": "webpack-dev-server --env dist -p --progress",
    "start": "npm run serve:dev",
    "test": "NODE_ENV=dev jest --no-cache"
  },
  "repository": "",
  "author": "Carlos Vieira",
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "~6.4.0",
    "babel-polyfill": "~6.23.0",
    "babel-preset-es2015": "~6.24.0",
    "babel-preset-react": "~6.24.0",
    "babel-preset-stage-2": "~6.24.0",
    "copy-webpack-plugin": "^4.0.0",
    "copyfiles": "^1.0.0",
    "css-loader": "^0.26.4",
    "eslint": "^4.0.0",
    "eslint-plugin-react": "^7.0.0",
    "file-loader": "^0.9.0",
    "jest": "^22.4.0",
    "jquery": "^3.3.1",
    "resolve-url-loader": "^2.2.1",
    "rimraf": "^2.5.2",
    "sass-loader": "^3.2.3",
    "source-map-loader": "^0.2.1",
    "style-loader": "^0.13.2",
    "tether": "^1.4.3",
    "url-loader": "^0.5.9",
    "webpack-dev-server": "~2.4.0"
  },
  "dependencies": {
    "ajv": "^6.1.1",
    "autoprefixer": "^7.2.3",
    "axios": "^0.18.0",
    "babel-jest": "^22.4.0",
    "bootstrap": "^4.0.0",
    "child_process": "^1.0.2",
    "cssnano": "^3.10.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "fs": "0.0.1-security",
    "jest-webpack-alias": "^3.3.3",
    "jest-webpack-resolver": "^0.2.0",
    "js-cookie": "~2.1.0",
    "jsdom": "^11.6.2",
    "less": "^2.7.3",
    "less-loader": "^4.0.5",
    "location": "0.0.1",
    "navigator": "^1.0.1",
    "node-sass": "^3.13.1",
    "normalize-scss": "~7.0.0",
    "popper.js": "^1.12.9",
    "postcss-cssnext": "^3.0.2",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.9",
    "precss": "^2.0.0",
    "prop-types": "~15.5.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-redux": "~5.0.0",
    "react-router": "~4.1.0",
    "react-router-dom": "~4.1.0",
    "react-transition-group": "~1.1.0",
    "redux": "~3.6.0",
    "redux-thunk": "~2.2.0",
    "regenerator-runtime": "^0.11.1",
    "resolve": "^1.5.0",
    "sugarss": "^1.0.1",
    "utils": "^0.3.1",
    "webpack": "^3.11.0"
  },
  "jest": {
    "haste": {
      "providesModuleNodeModules": [
        "node_modules"
      ]
    },
    "moduleDirectories": [
      "node_modules"
    ],
    "transform": {
      ".*": "./tests/preprocessor.js"
    },
    "modulePaths": [
      "src"
    ],
    "resolver": "jest-webpack-resolver",
    "collectCoverageFrom": [
      "**/*.{js,jsx}",
      "!**/node_modules/**",
      "!**/vendor/**"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/node_modules/"
    ]
  }
}

preprocessor.js

var babelJest = require('babel-jest');
require('babel-register'); // support ES6 'import' statements 
var webpackAlias = require('jest-webpack-alias');

module.exports = {
  process: function(src, filename, ...rest) {
    if (filename.indexOf('node_modules') === -1) {
      src = babelJest.process(src, filename, ...rest);
      src = webpackAlias.process(src, filename, ...rest);
    }
    return src;
  }
};

我需要一些帮助 我已经尝试删除所有节点模块并使用yarn或npm

进行安装 提前谢谢 卡洛斯维埃拉

我已删除节点模块并将jest升级到22版本 和应用纱线安装,但仍然是相同的错误。

1 个答案:

答案 0 :(得分:3)

jest issues

复制
  

我发现了这个问题。我从Jest配置中删除了“js”作为文件扩展名,因为我只有“ts”文件。你不能这样做。再次添加“js”可以解决我的问题。

请尝试在package.json中添加以下行。 "jest": { "moduleFileExtensions": [ "ts", "js" ] }