Closed Freed-Wu closed 6 months ago
Removing the const __dirname = path.dirname(fileURLToPath(import.meta.url));
line from index.js
in my node_modules folder temporarily fixed this for me since the __dirname
variable is included with node by default. I found a similar issue on another repo and there the fix was to use __dirname
instead of import.meta.url
.
@sindresorhus is a fix in sight for this?
The problem is with people's bundler config, not this package. There is nothing to fix here.
The problem is with people's bundler config
This is my esbuild.mjs
. Can you help me find the problem? TIA!
import fs from "fs";
import * as esbuild from "esbuild";
const loadJSON = (path) =>
JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
const data = loadJSON("package.json");
const options = {
entryPoints: ["src/index.ts"],
bundle: true,
minify: process.env.NODE_ENV === "production",
sourcemap: process.env.NODE_ENV === "development",
mainFields: ["module", "main"],
external: ["coc.nvim"],
platform: "node",
target: "node16",
outfile: data.main,
};
if (process.argv.length > 2 && process.argv[2] === "--watch") {
const ctx = await esbuild.context(options);
await ctx.watch();
console.log("watching...");
} else {
const result = await esbuild.build(options);
if (result.errors.length) {
console.error(result.errors);
}
}
The problem is with people's bundler config
This is my
esbuild.mjs
. Can you help me find the problem? TIA!import fs from "fs"; import * as esbuild from "esbuild"; const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url))); const data = loadJSON("package.json"); const options = { entryPoints: ["src/index.ts"], bundle: true, minify: process.env.NODE_ENV === "production", sourcemap: process.env.NODE_ENV === "development", mainFields: ["module", "main"], external: ["coc.nvim"], platform: "node", target: "node16", outfile: data.main, }; if (process.argv.length > 2 && process.argv[2] === "--watch") { const ctx = await esbuild.context(options); await ctx.watch(); console.log("watching..."); } else { const result = await esbuild.build(options); if (result.errors.length) { console.error(result.errors); } }
I was able to fix it by adding the following lines to my esbuild options:
define: { 'import.meta.url': '_importMetaUrl' },
banner: {
js: "const _importMetaUrl=require('url').pathToFileURL(__filename)",
},
After
yarn build
, I test and get:So I search
/the/path/lib/index.js:3627:84
, and find:The last line is 3627. It looks like a bug about
node_modules/open/index.js
, So I report it.