我不得不切换到导入,从browserify切换到了webpack。这是我在CLIENTSIDE上的Webpack配置。如果我执行module.exports,它将显示模块未定义...当然,我只是将其切换为导出默认设置。
我的模块中有类型:“package.json”。
对这里的解决方案有什么想法吗?我认为dirname来自节点"path“模块。我实际上不知道如何在浏览器之外的客户端获得绝对目录值……不能使用"“或"./”或"/“。不允许相对路径。
谢谢!
未捕获ReferenceError:未定义__dirname
// webpack.config.js
export default {
mode: "development",
entry: ["./src/index.js", "./src/index.css"],
output: {
path: __dirname,
publicPath: "/",
filename: "./dist/bundle.js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "script-loader",
},
},
{
test: /\.css$/,
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
options: {
modules: true,
importLoaders: 1,
sourceMap: true,
},
},
],
},
],
},
};发布于 2021-04-05 13:24:55
在你的代码中间接尝试这种方式,而不是从你的package.json。如果有效,请让我知道。
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);https://stackoverflow.com/questions/66948356
复制相似问题