-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: __require.resolve is not a function #369
Comments
The Your "solution" about |
Hello! I had the same problem at the moment I just disable the code splitting to have the code working. Did you have another solution? |
Share my solution "scripts": {
- "build": "tsup"
+ "build": "tsup && node fix.js"
} // fix.js
const beforeStr = `var __require = (x) => {
if (typeof require !== "undefined")
return require(x);
throw new Error('Dynamic require of "' + x + '" is not supported');
};`
const replacedContent = `
${beforeStr}
if (typeof require !== "undefined") {
__require = require
}
`
const res = str.replace(beforeStr, replacedContent) |
After reading the source code of tsup, I found that there is workaround "scripts": {
- "build": "tsup"
+ "build": "tsup --format cjs --no-splitting"
} Using --format alone won't work, you need --no-splitting Then the code can go to output as expected |
@screetBloom Yes that should work, but it will lose code splitting. |
Yes, but code splitting in esbuild must be esm When we use |
But admittedly, esbuild's default |
Also I think splitting should be false when |
Since esbuild 0.12.26, this issue should be solved automatically by updating dependencies. ( |
@hyrious Yes, working as expected! Thank you! |
Hello! I have an issue with the
tsup
, I have a TypeScript project withrequire.resolve
function, with puretsc
it works, but when I try to build withtsup-node
I get this error:I made a reproduction repo for this issue:
https://github.com/mvrlin/tsup-require-resolve
I came across this "solution":
The text was updated successfully, but these errors were encountered: