You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rollup config breaks some third-party libraries #3071
When the preset is cloudflare-module, PapaParse ends up with incorrectly nested double quotes, and Nitro fails to build with the error: ERROR Expected ',', got 'undefined'.
I first encountered this in Nuxt, and I'm able to work around this particular issue by applying this setting in the Nuxt config:
I don't think it's a double transform issue, though -- this would arise from a single transform. The package contains a line of code that's something like
I don't see the issue in .output/server; that directory is empty. (I think the build fails before emitting anything there?)
I see the issue in the full log output; sorry, here that is:
npm run build
> build
> nitro build
✔ Generated public .output/public nitro 11:04:56 AM
ℹ Building Nitro Server (preset: cloudflare-module, compatibility date: 2025-01-31) nitro 11:04:56 AM
ERROR RollupError: Expected ',', got 'undefined' in [...]/nitro/node_modules/papaparse/papaparse.js nitro 11:04:56 AM
50: var URL = global.URL || global.webkitURL || null;
51: var code = moduleFactory.toString();
52: return Papa.BLOB_URL || (Papa.BLOB_URL = URL.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if ("undefined"...
^
53: }
ERROR Expected ',', got 'undefined' in [...]/nitro/node_modules/papaparse/papaparse.js 11:04:56 AM
at getRollupError (node_modules/rollup/dist/es/shared/parseAst.js:397:41)
at convertProgram (node_modules/rollup/dist/es/shared/parseAst.js:1085:26)
at parseAst (node_modules/rollup/dist/es/shared/parseAst.js:2070:87)
at tryParse (node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12)
at analyzeTopLevelStatements (node_modules/@rollup/plugin-commonjs/dist/es/index.js:37:15)
at Object.transformAndCheckExports (node_modules/@rollup/plugin-commonjs/dist/es/index.js:2113:68)
at Object.transform (node_modules/@rollup/plugin-commonjs/dist/es/index.js:2317:41)
at node_modules/rollup/dist/es/shared/node-entry.js:21838:40
ERROR Expected ',', got 'undefined' in [...]/nitro/node_modules/papaparse/papaparse.js
I tried npm run build --preset cloudflare-module and the build completed successfully, but still nothing was generated in the server directory. (I have preset set in the config; I linked adorack/nitro-error@fe1f99f in the ticket description, which is the diff from the starter project.)
Oh, weird -- I do see output in cloudflare-module/.output/server -- but it doesn't look like this is pulling in PapaParse; I don't see the offending code fragment at all.
cloudflare-module/.output/server it seems wrong build/rootDir.
Your issue stands correct and I checked locally, it happens for any builds without having external (output/server/node_modules) support, and cloudflare is currently one of them.
Your solution is also nice. Sadly we cannot either change or drop this change as it breaks other places that depend on this tree-shaking method. If you like to contribute to docs perhaps additing a section to end of cloudflare.md it is more than welcome 🙏🏼
Sadly we cannot either change or drop this change as it breaks other places that depend on this tree-shaking method.
I'm happy to make a small docs PR (probably tomorrow at this point). However, is there any further explanation for what this tree-shaking accomplishes that I can link to or describe? Is it that it's somehow allowing a compiler to exclude branches that are client-only or server-only, and that compiler refuses to make assumptions about the window object?
This is indeed a bug. Replacing arbitrary code like this globally and without considering the AST will inevitably lead to incredibly difficult to debug problems. This bug is also triggered in combination with effect: Effect-TS/effect#3864
In our case, this configuration causes typeof window to be replaced in a string which it should absolutely not do.
Reacted by James Cullum (Pseudonym), Nicholai Nissen, Eason Shimmer and Gabriel
Activity
pi0 commentedon Feb 6, 2025
I'm worndering if it is double transform with wranger deploy. Can you spot same issue in
.output/dist/_workeralso?adorack commentedon Feb 6, 2025
Hello -- thanks for the quick response! I'm not sure exactly what you mean...
.outputdoesn't contain any files in my Nitro build:adorack commentedon Feb 6, 2025
I don't think it's a double transform issue, though -- this would arise from a single transform. The package contains a line of code that's something like
When Rollup applies its search-and-replace, the resulting source code is
This causes a syntax error when the build process actually tries to parse the module.
pi0 commentedon Feb 6, 2025
Nitro output for
cloudflare-modulepresets goes into.output/server/*dir.Do you see this issue in a file inside
.output/server/*files when usingbuild --preset cloudflare-module(consider before deploy, wrangler always does another transform step)
adorack commentedon Feb 6, 2025
I don't see the issue in
.output/server; that directory is empty. (I think the build fails before emitting anything there?)I see the issue in the full log output; sorry, here that is:
adorack commentedon Feb 6, 2025
I tried
npm run build --preset cloudflare-moduleand the build completed successfully, but still nothing was generated in theserverdirectory. (I havepresetset in the config; I linked adorack/nitro-error@fe1f99f in the ticket description, which is the diff from the starter project.)adorack commentedon Feb 6, 2025
Oh, weird -- I do see output in
cloudflare-module/.output/server-- but it doesn't look like this is pulling in PapaParse; I don't see the offending code fragment at all.pi0 commentedon Feb 6, 2025
cloudflare-module/.output/serverit seems wrong build/rootDir.Your issue stands correct and I checked locally, it happens for any builds without having external (
output/server/node_modules) support, and cloudflare is currently one of them.Your solution is also nice. Sadly we cannot either change or drop this change as it breaks other places that depend on this tree-shaking method. If you like to contribute to docs perhaps additing a section to end of cloudflare.md it is more than welcome 🙏🏼
adorack commentedon Feb 6, 2025
OK -- thank you for looking into it.
I'm happy to make a small docs PR (probably tomorrow at this point). However, is there any further explanation for what this tree-shaking accomplishes that I can link to or describe? Is it that it's somehow allowing a compiler to exclude branches that are client-only or server-only, and that compiler refuses to make assumptions about the
windowobject?pi0 commentedon Feb 6, 2025
Yes exactly it is to guide compiler to remove such branches. Both to eliminate code and remove incompatible code paths.
fubhy commentedon Feb 16, 2025
This is indeed a bug. Replacing arbitrary code like this globally and without considering the AST will inevitably lead to incredibly difficult to debug problems. This bug is also triggered in combination with
effect: Effect-TS/effect#3864In our case, this configuration causes
typeof windowto be replaced in a string which it should absolutely not do.pi0x commentedon Sep 7, 2026
Fixed in v3 — Nitro no longer replaces
typeof windowin the bundle, so string literals containing it are left alone; the only default replacements are theimport.meta.*flags in https://github.com/nitrojs/nitro/blob/main/src/build/config.ts.Triaged with AI assistance.