Open ScreamZ opened 4 months ago
I ran into this issue as well. Here is a workaround using a simple esbuild plugin. I'll likely publish this as well as an npm module, but here it is for now. Note that it is not foolproof, as you could have an installed module with the same name as a node built-in, but in most cases it should work, and you could always adjust the regex if necessary.
import { defineConfig } from 'tsup';
const NODE_BUILTIN_MODULE_REGEX = /^(assert|buffer|child_process|cluster|crypto|dgram|dns|domain|events|fs|http|https|net|os|path|punycode|querystring|readline|stream|string_decoder|timers|tls|tty|url|util|v8|vm|zlib)$/;
// plugin to add missing `node:` prefix - which is required for deno
function addNodeImportPrefix() {
return {
name: 'addNodeImportPrefix',
setup(build) {
build.onResolve({ filter: NODE_BUILTIN_MODULE_REGEX }, (args) => ({
path: `node:${args.path}`,
external: true,
}))
},
}
}
export default defineConfig({
// ...
esbuildPlugins: [addNodeImportPrefix()],
});
Using
shim: true
generateBut deno complains with syntax
"path"
and required"node:path"
is there any way to change this ?If you want to use a built-in Node module, add a "node:" prefix (ex. "node:path").
Upvote & Fund