travis 无法构建,因为错误:找不到module“react-test-renderer/shallow”

IT技术 reactjs npm build travis-ci enzyme
2021-05-12 21:54:20

npm run test本地工作正常。

但是,travis 坚持认为构建失败并显示以下日志:

react-test-renderer is an implicit dependency in order to support react@15.5+. Please add the appropriate version to your devDependencies. See https://github.com/airbnb/enzyme#installation
No coverage information was collected, exit without writing coverage information
/home/travis/build/abdennour/react-csv/node_modules/enzyme/build/react-compat.js:159
      throw e;
      ^
Error: Cannot find module 'react-test-renderer/shallow'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /home/travis/build/abdennour/react-csv/node_modules/enzyme/build/react-compat.js:151:34
    at Object.<anonymous> (/home/travis/build/abdennour/react-csv/node_modules/enzyme/build/react-compat.js:219:5)

任何的想法 ?知道我的依赖项是:

  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-core": "^6.18.2",
    "babel-istanbul": "^0.11.0",
    "babel-loader": "^6.2.8",
    "babel-plugin-react-html-attrs": "^2.0.0",
    "babel-plugin-syntax-decorators": "^6.13.0",
    "babel-plugin-transform-class-properties": "^6.19.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
    "babel-polyfill": "^6.16.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-3": "^6.16.0",
    "browserify": "^13.3.0",
    "console-info": "0.0.4",
    "coveralls": "^2.11.15",
    "css-loader": "^0.26.1",
    "enzyme": "^2.6.0",
    "expect": "^1.20.2",
    "extract-text-webpack-plugin": "^1.0.1",
    "isparta-loader": "^2.0.0",
    "jsdom": "9.8.3",
    "jsdom-global": "2.1.0",
    "mocha": "^3.2.0",
    "mocha-lcov-reporter": "^1.2.0",
    "react": "^15.4.1",
    "react-addons-test-utils": "^15.4.1",
    "react-docgen": "^2.13.0",
    "react-dom": "^15.4.1",
    "react-styleguidist": "^4.6.3",
    "sass-loader": "^4.0.2",
    "sinon": "^1.17.6",
    "style-loader": "^0.13.1",
    "uglify-js": "^2.7.5",
    "webpack": "^1.13.3",
    "webpack-dev-middleware": "^1.8.4",
    "webpack-dev-server": "^1.16.2",
    "webpack-hot-middleware": "^2.13.2"
2个回答

今天也遇到了同样的问题。

看起来 react-addons-test-utils 已被弃用https://www.npmjs.com/package/react-addons-test-utils

您可能可以将 package.json 中的那一行替换为

"react-test-renderer": "^15.5.4"

https://www.npmjs.com/package/react-test-renderer

希望有帮助!

只是我想详细说明@Anthony 的答案并深入研究它:

所以,这是应该完成的所有更新

  • 升级 reactreact-domenzyme

  • 替换 react-addons-test-utilsreact-test-renderer

在此处输入图片说明

在这里构建经特拉维斯传递。