Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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
Javascript 未找到模块:错误:Can';t解析'/节点模块/react';在'/用户/<;用户名>/文件/礼物测试/客户';_Javascript_Reactjs_Webpack_React Redux_Webpack Dev Server - Fatal编程技术网

Javascript 未找到模块:错误:Can';t解析'/节点模块/react';在'/用户/<;用户名>/文件/礼物测试/客户';

Javascript 未找到模块:错误:Can';t解析'/节点模块/react';在'/用户/<;用户名>/文件/礼物测试/客户';,javascript,reactjs,webpack,react-redux,webpack-dev-server,Javascript,Reactjs,Webpack,React Redux,Webpack Dev Server,因此,对于我的项目(使用React和Redux),我一直有“找不到模块”的错误。我用google的d&stackoverflow设计了几个解决方案,看到有人说我的node_模块出了问题,所以我删除了它们,还安装了npm(重新安装)。错误仍然存在,我认为这与我的webpack.config.js文件有关 我只是想让构建正常工作,让react元素和组件渲染 错误 Module not found: Error: Can't resolve './node_modules/react' in '/Us

因此,对于我的项目(使用React和Redux),我一直有“找不到模块”的错误。我用google的d&stackoverflow设计了几个解决方案,看到有人说我的node_模块出了问题,所以我删除了它们,还安装了npm(重新安装)。错误仍然存在,我认为这与我的webpack.config.js文件有关

我只是想让构建正常工作,让react元素和组件渲染

错误

Module not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 1:0-41 15:21-26 17:16-21

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react-dom' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 2:0-50 15:0-6

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react-redux' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 3:0-54 15:41-49

ERROR in ./client/store.js
Module not found: Error: Can't resolve './node_modules/redux' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/store.js 1:0-68 7:12-23
 @ ./client/index.js

ERROR in ./client/store.js
Module not found: Error: Can't resolve './node_modules/redux-devtools-extension' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/store.js 2:0-78 7:34-53
 @ ./client/index.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    //start at entry
    entry: './client/index.js',
    // devtool: "eval-source-map",
    mode: process.env.NODE_ENV,
    //Run these rules on it & go through the loaders
    module: {
        rules: [
            { test: /\.svg$/, use: 'svg-inline-loader' },
            { test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
            { test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react'],
                        // plugins: ['@babel/plugin-proposal-object-rest-spread']
                    }
                }
            },
        ]
    }, 
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },
        resolve: {
        extensions: ['.js', '.jsx'],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'client/index.html'
        })
    ],  
    devServer: {
        publicPath: "/build/",
        proxy: {
            'api':'http://localhost:3000',
        },
    },  
    resolve: {
        extensions: ['.js', '.jsx'],
    },
}
import React from './node_modules/react';
import { render } from './node_modules/react-dom';
import { Provider } from './node_modules/react-redux';
import App from './App.jsx';
import store from './store.js';
// import styles from './index.css'
// import './index.css';

render(
    <Provider store = {store}>
        <App/>
    </Provider>,
    document.getElementById('app')
);
包的开始部分.json

{
  "name": "gift-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "cross-env NODE_ENV=production webpack-dev-server --open",
    "build": "cross-env NODE_ENV=production webpack",
    "dev": "cross-env NODE_ENV=development concurrently \"nodemon server/server.js\" \"webpack-dev-server --open\" "
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ]
  }
Index.js

Module not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 1:0-41 15:21-26 17:16-21

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react-dom' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 2:0-50 15:0-6

ERROR in ./client/index.js
Module not found: Error: Can't resolve './node_modules/react-redux' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/index.js 3:0-54 15:41-49

ERROR in ./client/store.js
Module not found: Error: Can't resolve './node_modules/redux' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/store.js 1:0-68 7:12-23
 @ ./client/index.js

ERROR in ./client/store.js
Module not found: Error: Can't resolve './node_modules/redux-devtools-extension' in '/Users/<user-name>/Documents/gift-test/client'
 @ ./client/store.js 2:0-78 7:34-53
 @ ./client/index.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    //start at entry
    entry: './client/index.js',
    // devtool: "eval-source-map",
    mode: process.env.NODE_ENV,
    //Run these rules on it & go through the loaders
    module: {
        rules: [
            { test: /\.svg$/, use: 'svg-inline-loader' },
            { test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
            { test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react'],
                        // plugins: ['@babel/plugin-proposal-object-rest-spread']
                    }
                }
            },
        ]
    }, 
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },
        resolve: {
        extensions: ['.js', '.jsx'],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'client/index.html'
        })
    ],  
    devServer: {
        publicPath: "/build/",
        proxy: {
            'api':'http://localhost:3000',
        },
    },  
    resolve: {
        extensions: ['.js', '.jsx'],
    },
}
import React from './node_modules/react';
import { render } from './node_modules/react-dom';
import { Provider } from './node_modules/react-redux';
import App from './App.jsx';
import store from './store.js';
// import styles from './index.css'
// import './index.css';

render(
    <Provider store = {store}>
        <App/>
    </Provider>,
    document.getElementById('app')
);

因为您需要作为依赖项安装react。要安装,只需执行此命令
npm i react


回答:像这样导入react
从“react”导入react

尝试以下操作:
从“React”导入React从导入中删除
/node\u模块
!实际上,我甚至没有意识到。/node\u模块在那里。。。。。我发誓我没有把它们加在那里哈哈。。。搞什么鬼。