错误./node_modules/ts-invariant/process/index.js 24:33-40
我在创建构建时会遇到此错误。
打破变化:
请求“过程/浏览器”无法解决仅因为它是 按照完全指定的解决方案解决(可能是因为起源很严格 eCmascript模块,例如带有JavaScript MimeType的模块,A' .mjs' 文件或' .js'文件,其中包含'type”: “模块”')。请求中的扩展名是必不可少的 完全指定。将扩展名添加到请求中。解决 “路径”中的“过程/浏览器”
这是我的webpack.config文件
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { outputConfig, copyPluginPatterns, entryConfig, devServer } = require("./env.config");
const webpack = require('webpack');
require('dotenv').config({ path: './.env' });
module.exports = (env, options) =>
{
return {
mode: options.mode,
entry: entryConfig,
devServer,
target: "web",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
{
test: /\.(css|scss)$/,
use: [
// We're in dev and want HMR, SCSS is handled in JS
// In production, we want our css as files
"style-loader",
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
["postcss-preset-env"],
],
},
},
},
"sass-loader"
],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|svg)$/i,
type: "javascript/auto",
loader: "file-loader",
options: {
publicPath: "../",
name: "[path][name].[ext]",
context: path.resolve(__dirname, "src/assets"),
emitFile: false,
},
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: "javascript/auto",
exclude: /images/,
loader: "file-loader",
options: {
publicPath: "../",
context: path.resolve(__dirname, "src/assets"),
name: "[path][name].[ext]",
emitFile: false,
},
},
],
},
resolve: { extensions: [".tsx", ".ts", ".js",".jsx",".json"],fallback: {
path: false,
buffer: false,
crypto: false
},alias: {
process: "process/browser"
}
},
output: {
filename: "js/[name].bundle.js",
path: path.resolve(__dirname, outputConfig.destPath),
publicPath: "",
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
inject: true,
minify: false
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env)
}),
new CopyPlugin(copyPluginPatterns),
new webpack.ProvidePlugin({
process: 'process/browser',
})
]
};
};`
I am getting this error while creating a build.
BREAKING CHANGE:
The request 'process/browser' failed to resolve only because it was
resolved as fully specified (probably because the origin is strict
EcmaScript Module, e. g. a module with javascript mimetype, a '.mjs'
file, or a '.js' file where the package.json contains '"type":
"module"'). The extension in the request is mandatory for it to be
fully specified. Add the extension to the request. resolve
'process/browser' in 'Path'
Here is my webpack.config file
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { outputConfig, copyPluginPatterns, entryConfig, devServer } = require("./env.config");
const webpack = require('webpack');
require('dotenv').config({ path: './.env' });
module.exports = (env, options) =>
{
return {
mode: options.mode,
entry: entryConfig,
devServer,
target: "web",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
{
test: /\.(css|scss)$/,
use: [
// We're in dev and want HMR, SCSS is handled in JS
// In production, we want our css as files
"style-loader",
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
["postcss-preset-env"],
],
},
},
},
"sass-loader"
],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|svg)$/i,
type: "javascript/auto",
loader: "file-loader",
options: {
publicPath: "../",
name: "[path][name].[ext]",
context: path.resolve(__dirname, "src/assets"),
emitFile: false,
},
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: "javascript/auto",
exclude: /images/,
loader: "file-loader",
options: {
publicPath: "../",
context: path.resolve(__dirname, "src/assets"),
name: "[path][name].[ext]",
emitFile: false,
},
},
],
},
resolve: { extensions: [".tsx", ".ts", ".js",".jsx",".json"],fallback: {
path: false,
buffer: false,
crypto: false
},alias: {
process: "process/browser"
}
},
output: {
filename: "js/[name].bundle.js",
path: path.resolve(__dirname, outputConfig.destPath),
publicPath: "",
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
inject: true,
minify: false
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env)
}),
new CopyPlugin(copyPluginPatterns),
new webpack.ProvidePlugin({
process: 'process/browser',
})
]
};
};`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过在字符串中添加
.js
后缀来解决错误。之前:
之后:
I was able to solve the error by adding the
.js
suffix to the string.Before:
After: