首页 > 解决方案 > 错误(“webpack-cli”ReferenceError: navigator is not defined),当运行`npm run prod or dev'

问题描述

不知道发生了什么,但我真的坚持这一点。问题是当我跑步npm run prod或遇到npm run dev以下错误时:

> prod
> npm run production


> production
> mix --production

[webpack-cli] ReferenceError: navigator is not defined
    at \\\\\\path_of_my_project\\\\\\\\webpack.mix.js:26:390
    at Object.<anonymous> (\\\\\\path_of_my_project\\\\\\\\webpack.mix.js:26:780)
    at Module._compile (\\\\\\path_of_my_project\\\\\\\\node_modules\v8-compile-cache\v8-compile-c
ache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (\\\\\\path_of_my_project\\\\\\\\node_modules\v8-compile-cache\v8-compile-cache.js:
159:20)
    at module.exports (\\\\\\path_of_my_project\\\\\\\\node_modules\laravel-mix\setup\webpack.conf
ig.js:8:5)
    at \\\\\\path_of_my_project\\\\\\\\node_modules\webpack-cli\lib\webpack-cli.js:1565:43

这就是我发现的npm audit:-

>npm audit
# npm audit report

css-what  <5.0.1
Severity: high
Denial of Service - https://npmjs.com/advisories/1754
fix available via `npm audit fix --force`
Will install laravel-mix@5.0.9, which is a breaking change
node_modules/css-what
  css-select  <=3.1.2
  Depends on vulnerable versions of css-what
  node_modules/css-select
    svgo  >=1.0.0
    Depends on vulnerable versions of css-select
    node_modules/svgo
      postcss-svgo  >=4.0.0-nightly.2020.1.9
      Depends on vulnerable versions of svgo
      node_modules/postcss-svgo
        cssnano-preset-default  *
        Depends on vulnerable versions of postcss-svgo
        node_modules/cssnano-preset-default
          cssnano  >=4.0.0-nightly.2020.1.9
          Depends on vulnerable versions of cssnano-preset-default
          node_modules/cssnano
            laravel-mix  5.0.8 || >=6.0.0-alpha.0
            Depends on vulnerable versions of cssnano
            node_modules/laravel-mix

7 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

这是我的 package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "axios": "^0.21.1",
        "bootstrap": "^4.5.3",
        "browser-sync": "^2.26.12",
        "browser-sync-webpack-plugin": "^2.2.2",
        "cross-env": "^7.0.2",
        "jquery": "^3.5.1",
        "jquery-scroll-lock": "^3.1.3",
        "jquery.appear": "^1.0.1",
        "js-cookie": "^2.2.1",
        "laravel-echo": "^1.9.0",
        "laravel-mix": "^6.0.25",
        "lodash": "^4.17.20",
        "popper.js": "^1.16.1",
        "pusher-js": "^7.0.0",
        "resolve-url-loader": "^3.1.0",
        "sass": "^1.27.0",
        "sass-loader": "^10.0.3",
        "simplebar": "^5.2.1",
        "sweetalert2": "^10.6.1",
        "vue": "^2.6.12",
        "vue-template-compiler": "^2.6.12"
    },
    "dependencies": {
        "@fortawesome/fontawesome-free": "^5.15.1",
        "magnific-popup": "^1.1.0",
        "request": "2.88.2"
    }
}

我只尝试清除缓存npm cache clean --force但没有任何反应。**我的 npm 版本是:7.16.0 而 Laravel 版本是:“^8.0” **

标签: npmlaravel-8

解决方案


推荐阅读