“找不到模块:错误:无法解析模块‘react/lib/ReactMount’" [英] "module not found : Error: Cannot resolve module 'react/lib/ReactMount' "

查看:42
本文介绍了“找不到模块:错误:无法解析模块‘react/lib/ReactMount’"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Reactjs和webpack启动了一个项目,在命令提示符下运行node server"时,出现这样的错误:

I used Reactjs and webpack to start a project, and when I run the "node server" in the command prompt, there is an error like this:

并且chrome explorer打开成功但也有如下问题:

And the chrome explorer opened successful but also have problems as follows:

github 为:(github.com/Yangqin0607/gallery)

The github is: (github.com/Yangqin0607/gallery)

这里是 package.json

Here is the package.json

    {
  "private": true,
  "version": "0.0.1",
  "description": "YOUR DESCRIPTION - Generated by generator-react-webpack",
  "main": "",
  "scripts": {
    "clean": "rimraf dist/*",
    "copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist",
    "dist": "npm run copy & webpack --env=dist",
    "lint": "eslint ./src",
    "posttest": "npm run lint",
    "release:major": "npm version major && npm publish && git push --follow-tags",
    "release:minor": "npm version minor && npm publish && git push --follow-tags",
    "release:patch": "npm version patch && npm publish && git push --follow-tags",
    "serve": "node server.js --env=dev",
    "serve:dist": "node server.js --env=dist",
    "start": "node server.js --env=dev",
    "test": "karma start",
    "test:watch": "karma start --autoWatch=true --singleRun=false"
  },
  "repository": "",
  "keywords": [],
  "author": "Your name here",
  "devDependencies": {
    "babel-core": "^6.0.0",
    "babel-eslint": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-polyfill": "^6.3.14",
    "babel-preset-es2015": "^6.0.15",
    "babel-preset-react": "^6.0.15",
    "babel-preset-stage-0": "^6.5.0",
    "bower-webpack-plugin": "^0.1.9",
    "chai": "^3.2.0",
    "copyfiles": "^1.0.0",
    "css-loader": "^0.23.0",
    "eslint": "^3.0.0",
    "eslint-loader": "^1.0.0",
    "eslint-plugin-react": "^6.0.0",
    "file-loader": "^0.9.0",
    "glob": "^7.0.0",
    "isparta-instrumenter-loader": "^1.0.0",
    "karma": "^1.0.0",
    "karma-chai": "^0.1.0",
    "karma-coverage": "^1.0.0",
    "karma-mocha": "^1.0.0",
    "karma-mocha-reporter": "^2.0.0",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.5",
    "karma-webpack": "^1.7.0",
    "minimist": "^1.2.0",
    "mocha": "^3.0.0",
    "null-loader": "^0.1.1",
    "open": "0.0.5",
    "phantomjs-prebuilt": "^2.0.0",
    "react-addons-test-utils": "^15.0.0",
    "react-hot-loader": "^1.2.9",
    "rimraf": "^2.4.3",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.6",
    "webpack": "^1.12.0",
    "webpack-dev-server": "^1.12.0"
  },
  "dependencies": {
    "core-js": "^2.0.0",
    "normalize.css": "^4.0.0",
    "react": "^15.0.0",
    "react-dom": "^15.0.0"
  }
}

推荐答案

此问题与 react-hot-loader 包有关.您使用的旧版本依赖于 node_modules/react/lib 文件夹中的 ReactMount.js 文件.

This issue is related to the react-hot-loader package. You are using an old version that relies on the ReactMount.js file being present in the node_modules/react/lib folder.

没有简单的方法可以解决这个问题,但您有以下几种选择:

There is no easy one way fix for that but you have a few options which are:

  1. 尝试按照此处的说明操作:https://github.com/gaearon/react-hot-loader/blob/v3.0.0-beta.6/docs/README.md#usage-with-外部反应(但到目前为止我一直不走运)

  1. Try to follow the instructions here: https://github.com/gaearon/react-hot-loader/blob/v3.0.0-beta.6/docs/README.md#usage-with-external-react (but I have been unlucky so far)

移除用于反应的热重载器(在你的 webpack.config 中移除 'react-hot' 加载器)

Remove the hot reloader for react (in your webpack.config remove the 'react-hot' loader)

react-hot-loader 包更新到第 3 版(操作方法如下:https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16710935f17c>但请注意,这个包已经有一段时间处于 alpha 阶段了...

Update the react-hot-loader package to version 3 (here is how to do so: https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915). But note that this package has been in alpha for a while now...

将您的 React 版本回滚到 lib 文件夹中包含 ReactMount.js 的版本(15.0.1 过去,此文件不确定何时停止).

Rollback your react version to one that includes the ReactMount.js in the lib folder (15.0.1 used to have this file not sure when it stopped).

更新: React Hot Loader 3 现在处于测试阶段,提供更全面的升级指南:https://github.com/gaearon/react-hot-loader/tree/v3.0.0-beta.7/docs#迁移到 30

Update: React Hot Loader 3 is now in beta with a more comprehensive upgrade guide: https://github.com/gaearon/react-hot-loader/tree/v3.0.0-beta.7/docs#migration-to-30

这篇关于“找不到模块:错误:无法解析模块‘react/lib/ReactMount’"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆