【问题标题】:Module not found: Error: Can't resolve 'os' in未找到模块:错误:无法解析 'os' in
【发布时间】:2021-11-07 15:25:01
【问题描述】:

我正在开发一个 Laravel/Vue3 项目。当我运行“npm run dev”时,突然收到 37 条错误消息。我认为这与 mix 或 webpack 的配置有关。但我不是这方面的专家。很可能我犯了一个简单的错误,但我找不到它。

前几条错误信息(总共有 37 条!):

 npm run development


> @ development C:\xampp\htdocs\testBankjes
> mix

i Compiling Mix
 Mix: Compiled with some errors in 2.18s
WARNING in ./node_modules/laravel-mix/src/Dependencies.js 138:16-37
Critical dependency: the request of a dependency is an expression

ERROR in ./node_modules/clean-css/lib/options/format.js 1:22-39
Module not found: Error: Can't resolve 'os' in 'C:\xampp\htdocs\testBankjes\node_modules\clean-css\lib\options'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
        - install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "os": false }

ERROR in ./node_modules/clean-css/lib/options/rebase-to.js 1:11-26
Module not found: Error: Can't resolve 'path' in 'C:\xampp\htdocs\testBankjes\node_modules\clean-css\lib\options'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ./node_modules/clean-css/lib/reader/apply-source-maps.js 1:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\xampp\htdocs\testBankjes\node_modules\clean-css\lib\reader'

ERROR in ./node_modules/clean-css/lib/reader/apply-source-maps.js 2:11-26
Module not found: Error: Can't resolve 'path' in 'C:\xampp\htdocs\testBankjes\node_modules\clean-css\lib\reader'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

我的 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": {
        "@vue/compiler-sfc": "^3.2.8",
        "axios": "^0.21",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "vue-loader": "^16.5.0"
    },
    "dependencies": {
        "@fortawesome/fontawesome-svg-core": "^1.2.36",
        "@fortawesome/free-solid-svg-icons": "^5.15.4",
        "@fortawesome/vue-fontawesome": "^3.0.0-4",
        "bootstrap": "^5.1.1",
        "leaflet": "^1.7.1",
        "mitt": "^3.0.0",
        "vue": "^3.2.8"
    }
}

还有我的 webpack.mix.js:

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

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .vue()
    .postCss('resources/css/app.css', 'public/css', [
        //
    ]);

非常感谢您的帮助。

休伯特

【问题讨论】:

    标签: javascript node.js npm webpack


    【解决方案1】:

    在您的 app.js 主文件中,查找以下代码行:

     import File from 'laravel-mix/src/File';
    

    删除该行代码,您的工作将成功编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-22
      • 2021-07-04
      • 2017-04-18
      • 2019-12-26
      • 2019-01-31
      • 1970-01-01
      • 2022-11-10
      • 2016-09-09
      相关资源
      最近更新 更多