最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

运行“npm run”时无法解析'react'

IT培训 admin 3浏览 0评论

运行“npm run”时无法解析'react'

我的项目最近开始抱怨它在我运行npm run dev脚本时无法解决反应,这是:cross-env NODE_ENV = development node_modules / webpack / bin / webpack.js --progress --hide-modules - 配置= node_modules / laravel混合/建立/ webpack.config.js

好像npm找不到node_modules目录?

它在我的Windows机器上运行正常,但是当我将它上传到Ubuntu服务器时,我得到错误。我尝试过各种各样的东西,比如删除node_modules和锁定文件,清理npm缓存,检查$ NODE_PATH,重新安装nodejs和npm无济于事。我无法弄清楚这是一个路径问题还是我在服务器上遗漏了什么或什么。

我很感激你有任何提示。

我的package.json:

{
    "private": true,
    "name": "Write.nogetdigitalt.dk",
    "version": "0.0.1",
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@fortawesome/react-fontawesome": "^0.1.3",
        "axios": "^0.18",
        "babel-preset-react": "^6.24.1",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.5",
        "moment": "^2.23.0",
        "popper.js": "^1.12",
        "react": "^16.5.2",
        "react-datepicker": "^2.0.0",
        "react-dom": "^16.5.2",
        "redux": "^4.0.1",
        "vue": "^2.5.7"
    },
    "dependencies": {
        "@fortawesome/free-solid-svg-icons": "^5.5.0",
        "react-icons": "^3.2.0"
    }
}

webpack.mix.js

const mix = require('laravel-mix');
const webpack = require('webpack');

mix.webpackConfig({
    resolve: {
        extensions: ['.js', 'jsx'],
        alias: {
            'react': 'React'
        }
    },
    plugins: [
        new webpack.ProvidePlugin({
            'React': 'react',
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Popper: ['popper.js', 'default']
        })
    ]
})
.disableNotifications()

.react('resources/js/app.js', 'public/js')
    .sourceMaps()
.sass('resources/sass/app.scss', 'public/css');

错误消息:

ERROR in ./resources/js/pages/Note/Note.js
Module not found: Error: Can't resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
  Parsed request is a module
  using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
    aliased with mapping 'react': 'React' to 'React'
      Parsed request is a module
      using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
        Field 'browser' doesn't contain a valid alias configuration
      after using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
        resolve as module
          /var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/js/pages/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/js/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/node_modules doesn't exist or is not a directory
          /var/www/html/node_modules doesn't exist or is not a directory
          /var/www/node_modules doesn't exist or is not a directory
          /var/node_modules doesn't exist or is not a directory
          /node_modules doesn't exist or is not a directory
回答如下:

对于其他任何遇到此类问题的人来说,不同操作系统之间的路径定义最好使用NodeJS的path

`const path = require('path');
[...]
resolve: {
        extensions: ['.js', 'jsx'],
        alias: {
            'react': path.resolve(__dirname, 'Path to your folder to alias')
        }
    }`

运行“npm run”时无法解析'react'

我的项目最近开始抱怨它在我运行npm run dev脚本时无法解决反应,这是:cross-env NODE_ENV = development node_modules / webpack / bin / webpack.js --progress --hide-modules - 配置= node_modules / laravel混合/建立/ webpack.config.js

好像npm找不到node_modules目录?

它在我的Windows机器上运行正常,但是当我将它上传到Ubuntu服务器时,我得到错误。我尝试过各种各样的东西,比如删除node_modules和锁定文件,清理npm缓存,检查$ NODE_PATH,重新安装nodejs和npm无济于事。我无法弄清楚这是一个路径问题还是我在服务器上遗漏了什么或什么。

我很感激你有任何提示。

我的package.json:

{
    "private": true,
    "name": "Write.nogetdigitalt.dk",
    "version": "0.0.1",
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@fortawesome/react-fontawesome": "^0.1.3",
        "axios": "^0.18",
        "babel-preset-react": "^6.24.1",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.5",
        "moment": "^2.23.0",
        "popper.js": "^1.12",
        "react": "^16.5.2",
        "react-datepicker": "^2.0.0",
        "react-dom": "^16.5.2",
        "redux": "^4.0.1",
        "vue": "^2.5.7"
    },
    "dependencies": {
        "@fortawesome/free-solid-svg-icons": "^5.5.0",
        "react-icons": "^3.2.0"
    }
}

webpack.mix.js

const mix = require('laravel-mix');
const webpack = require('webpack');

mix.webpackConfig({
    resolve: {
        extensions: ['.js', 'jsx'],
        alias: {
            'react': 'React'
        }
    },
    plugins: [
        new webpack.ProvidePlugin({
            'React': 'react',
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Popper: ['popper.js', 'default']
        })
    ]
})
.disableNotifications()

.react('resources/js/app.js', 'public/js')
    .sourceMaps()
.sass('resources/sass/app.scss', 'public/css');

错误消息:

ERROR in ./resources/js/pages/Note/Note.js
Module not found: Error: Can't resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
  Parsed request is a module
  using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
    aliased with mapping 'react': 'React' to 'React'
      Parsed request is a module
      using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
        Field 'browser' doesn't contain a valid alias configuration
      after using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
        resolve as module
          /var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/js/pages/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/js/node_modules doesn't exist or is not a directory
          /var/www/html/write.nogetdigitalt.dk/resources/node_modules doesn't exist or is not a directory
          /var/www/html/node_modules doesn't exist or is not a directory
          /var/www/node_modules doesn't exist or is not a directory
          /var/node_modules doesn't exist or is not a directory
          /node_modules doesn't exist or is not a directory
回答如下:

对于其他任何遇到此类问题的人来说,不同操作系统之间的路径定义最好使用NodeJS的path

`const path = require('path');
[...]
resolve: {
        extensions: ['.js', 'jsx'],
        alias: {
            'react': path.resolve(__dirname, 'Path to your folder to alias')
        }
    }`
发布评论

评论列表 (0)

  1. 暂无评论