简体   繁体   English

模块构建失败:TypeError:无法读取未定义的属性“上下文”-Webpack

[英]Module build failed: TypeError: Cannot read property 'context' of undefined - Webpack

I want to build my project我想建立我的项目

I wrote this code to build my project npm run build but i got this errors:我写了这段代码来构建我的项目 npm run build 但我收到了这个错误:

ERROR in ./src/public/webfonts/fa-solid-900.svg
Module build failed: TypeError: Cannot read property 'context' of undefined
    at Object.loader (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/file-loader/dist/index.js:34:49)
 @ ./node_modules/css-loader??ref--5-1!./src/public/css/fontawesome-all.css 7:72144-72185
 @ ./src/public/css/fontawesome-all.css
 @ ./src/index.js

ERROR in ./src/public/webfonts/fa-brands-400.svg
Module build failed: TypeError: Cannot read property 'context' of undefined
    at Object.loader (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/file-loader/dist/index.js:34:49)
 @ ./node_modules/css-loader??ref--5-1!./src/public/css/fontawesome-all.css 7:70780-70822
 @ ./src/public/css/fontawesome-all.css
 @ ./src/index.js

this is my webpack.config.js :这是我的webpack.config.js

const HtmlWebPackPlugin = require("html-webpack-plugin");

const htmlWebpackPlugin = new HtmlWebPackPlugin({
    template: "./public/index.html",
    filename: "./index.html"
});

module.exports = {
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "babel-loader",
            },
            {
                //test: /\.css$/,
                test:/\.(s*)css$/,
                use: [
                    {
                        loader: "style-loader"
                    },
                    {
                        loader: "css-loader",
                        options: {
                            modules: true,
                            importLoaders: 1,
                            localIdentName: "[name]_[local]_[hash:base64]",
                            sourceMap: true,
                            minimize: true
                        }
                    }
                ]
            },
            {
                test: /.(ttf|otf|eot|png|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit : 8192
                        }
                    }
                ]
            },
            {
                test: /.(ttf|otf|eot|png|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            outputPath: 'fonts/',
                            name: '[name][hash].[ext]'
                        }
                    }
                ]
            }
        ]
    },
    plugins: [htmlWebpackPlugin]
};

I don't know what the problem is!我不知道是什么问题!

My OS is macOS highSierra version 10.13.3我的操作系统是 macOS highSierra 版本 10.13.3
node js version 10节点js版本10
react version 16.2反应版本 16.2
I'm using npm version 6.0.1我正在使用 npm 版本 6.0.1
webpack version 4.网络包版本 4.

I think webpack does't know my font files (like ttf, otf, eot, etc...)我认为 webpack 不知道我的字体文件(如 ttf、otf、eot 等...)

This issue is because of a change introduced in webpack v4.这个问题是由于 webpack v4 中引入的更改。 Check this issue in Webpack github (Incompatible loaders section) .Webpack github(不兼容的加载程序部分)中检查此问题。 You can either go with the workaround that is suggested just below in the site which is to add another plugin as follows to your webpack config:您可以使用网站下方建议的解决方法,即在您的 webpack 配置中添加另一个插件,如下所示:

new LoaderOptionsPlugin({
  options: {
    context: process.cwd() // or the same value as `context`
  }
})

Or you can upgrade the version of file-loader to v1.1.6 in which this issue is resolved.或者您可以将file-loader的版本升级到v1.1.6以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模块构建失败:TypeError:无法在Object.module.exports中读取未定义的属性“context” - Module build failed: TypeError: Cannot read property 'context' of undefined at Object.module.exports 带有Webpack错误的React Storybook-模块构建失败:TypeError:无法读取未定义的属性'thisCompilation' - React Storybook with Webpack Error - Module build failed: TypeError: Cannot read property 'thisCompilation' of undefined 模块构建失败:TypeError:无法读取未定义的属性“newLine” - Module build failed: TypeError: Cannot read property 'newLine' of undefined Webpack 4 css模块TypeError:无法读取未定义的属性“context” - Webpack 4 css modules TypeError: Cannot read property 'context' of undefined 模块构建失败:TypeError:无法读取未定义的属性'exclude'(awesome-typescript-loader) - Module build failed: TypeError: Cannot read property 'exclude' of undefined(awesome-typescript-loader) 重新安装angular / cli后:模块构建失败:TypeError:无法读取未定义的属性'newLine' - after re-install angular/cli: Module build failed: TypeError: Cannot read property 'newLine' of undefined Webpack:TypeError:无法读取未定义的属性“属性” - Webpack: TypeError: Cannot read property 'properties' of undefined 带有 ES6 和 webpack 的 AngularJS 1.7 给出错误:未捕获的类型错误:无法读取未定义的属性“模块” - AngularJS 1.7 with ES6 and webpack giving error: Uncaught TypeError: Cannot read property 'module' of undefined Microsoft NodeJS从零到英雄:找不到模块'../build/Release/bson'和TypeError:无法读取未定义的属性'indexOf' - Microsoft NodeJS Zero to Hero: Cannot find module '../build/Release/bson' and TypeError: Cannot read property 'indexOf' of undefined Webpack Uncaught TypeError:无法读取未定义的属性“调用” - Webpack Uncaught TypeError: Cannot read property 'call' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM