加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

找不到模块:错误:当我使用webpack时无法解析模块’反应’

发布时间:2020-12-15 20:18:23 所属栏目:百科 来源:网络整理
导读:我真的很感激这方面的帮助: 我无法使用webpack构建,我得到一个简短的错误列表,从以下开始: Module not found: Error: Cannot resolve module 'react' in ../client/front_desk.jsx 最后得到一个长列表,如下所示: Module not found: Error: Cannot resolve
我真的很感激这方面的帮助:
我无法使用webpack构建,我得到一个简短的错误列表,从以下开始:

Module not found: Error: Cannot resolve module 'react' in ../client/front_desk.jsx

最后得到一个长列表,如下所示:

Module not found: Error: Cannot resolve 'file' or 'directory' ../node_modules/process/browser.js

这是我的webpack.config.js:

const webpack = require('webpack');
const commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');

module.exports = {
  entry: {
    front_desk: './front/client/front_desk',},resolve: {
    extensions: ['.js','.jsx'],output: {
    path: 'front/public/js',filename: '[name].js',// Template based on keys in entry above
  },module: {
    loaders: [
      {
        test: /.(jsx|js)?$/,loader: 'babel',query: {
          presets: ['es2015','react'],],plugins: [commonsPlugin],};

而我的.babelrc:

{
  "plugins": ["syntax-jsx"],"presets": ["react","es2015"],}

我的依赖项列表在package.json中:

"dependencies": {
    "aguid": "*","babel-plugin-syntax-jsx": "*","babel-preset-es2015": "*","babel-preset-react": "*","babel-register": "*","bcrypt": "*","eslint": "*","eslint-config-airbnb": "^8.0.0","eslint-plugin-import": "^1.6.1","eslint-plugin-jsx-a11y": "^1.0.4","eslint-plugin-react": "^5.0.1","hapi": "*","hapi-react-views": "^7.0.0","inert": "*","isomorphic-fetch": "*","mailparser": "*","mandrill-api": "*","mongodb": "*","nodemon": "*","react": "^15.0.2","react-dom": "^15.0.2","react-redux": "*","redux": "*","redux-thunk": "*","twilio": "*","vision": "*","webpack-dev-server": "^1.14.1"
  },"devDependencies": {
    "babel-core": "*","babel-loader": "*","faucet": "*","jsx-loader": "^0.13.2","tape": "*","webpack": "*"
  }

解决方法

弄清楚了!我首先使用–display-error-details运行webpack,在我看来应该一直默认启用. webpack –progress –color –watch –display-error-details.

这告诉我,webpack遇到这么困难的原因是因为我告诉它要寻找的扩展有问题:

resolve: {
    extensions: ['.js',

会寻找react.js.js和react.js.jsx而不仅仅是react.js.所以,我必须将其更新为:

resolve: {
    extensions: ['','.js',

哪个修好了! =)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读