-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Creating a build with vite causes method to be undefined #15319
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
Comments
|
It seems that // vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig(async ({ command }) => {
return {
build: {
rollupOptions: {
treeshake: false,
},
},
};
}); |
Thanks for the comment. It's good to know that it is treeshaking-related, but I certainly want to keep that turned on. I assume that means the source code needs to change and not have side effects? Are there good docs for where to start with understanding what's being treeshaked any why? |
You can refer to the document, which may be helpful for you. The import * as jsmNodes from 'three/examples/jsm/nodes/Nodes.js';
const {
mx_noise_vec3,
timerLocal,
MeshPhysicalNodeMaterial,
normalWorld,
} = jsmNodes; This issue seems to be unrelated to |
Turns out the three.js package already declares these particular files as having side effects in its
Is that ignored in vite? |
The |
I tried to use https://stackblitz.com/edit/vitejs-vite-pxc7td?file=rollup.config.js |
Only that exact single module is side effectful, all the modules re-exported from there aren't; If some of them are indeed side effectful, you should mark them in sideEffects, in your case: - "sideEffects": ["./examples/jsm/nodes/Nodes.js"],
+ "sideEffects": ["./examples/jsm/nodes/Nodes.js", "./examples/jsm/nodes/core/FunctionCallNode.js"], |
Yeah. According to my understanding, all modules in |
If this issue has been resolved, you can close it. @hybridherbst |
I checked the reproduction with the @XiSenao Thanks for investigating! |
Describe the bug
The code in the reproduction case only breaks when making a build. Local development works fine.
Related issue on the three.js side to keep track of it:
functionNode.call is not a function
mrdoob/three.js#27360I have tracked down the difference between local run and a build run being that
functionNode.call
is undefined in builds, but defined and working in local development:I am not 100% sure if this is a vite bug during bundling but I don't know where the discrepancy comes from.
Reproduction
https://stackblitz.com/edit/vitejs-vite-9b37bu
Steps to reproduce
Uncaught TypeError: functionNode.call is not a function
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.10.5 - /usr/local/bin/pnpm npmPackages: vite: ^5.0.4 => 5.0.7
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: