-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Works in Dev, Not in Prod - imported module has undefined exports #10612
Comments
Checkek out https://stackblitz.com/edit/vitejs-vite-nlwsq9?file=vite.config.js The old
var SipHash = (function () {
// ...
return {
hash: hash,
hash_hex: hash_hex,
hash_uint: hash_uint,
string16_to_key: string16_to_key,
string_to_u8: string_to_u8
};
})();
var module = module || {}, exports = module.exports = SipHash; The
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
{
name: "fix-siphash-exports",
transform(code, id) {
const siphashRE = /node_modules\/siphash\/lib\/.*\.js$/;
if(siphashRE.test(id)) {
return code.replace("var module = module || {},", "");
}
}
}
]
}) |
I tried to fix what Tanimodori explained today. Ultimately, it introduces quite some complexity and given that it's a really edge case, I don't think this is worth fixing. The library should try to avoid the syntax, especially that I'm going to close this as a wontfix, but if anyone is interested in fixing still, here's the rundown of where to fix it. As shown, This scope analysis is done here in The scope is created through its The utility assigns AST nodes that creates a scope with // Example case
var module = module || (() => module)(); other()
// |--------|
// new scope here (A*)
// |--------------|
// new scope but inherits from A (the existing code would take
// A* which is incorrect, this needs to be specially handled)
// |-------------------------------------------|
// parent scope (A)
|
Describe the bug
I am importing a package that has been installed via npm.
Development works fine
The package imports are undefined in production
Reproduction
https://stackblitz.com/edit/vitejs-vite-vtgp1g?file=main.js
Steps to reproduce
vite build
vite preview
check console in preview window and see that the logged module is empty
Note how dev had the module contents
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: