-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[commonjs-resolver] can not parse umd file properly (possibly)due to BOM marker #5258
Comments
Do you have an actual reproduction we can have a look at? E.g. something in the Rollup REPL? |
@lukastaegert It is a super complicate project, I am trying to strip it down |
Rollup doesn't throw an error if I pass in the content of lerc@3.0.0/LercDecode.js. |
I just encountered the exact same issue, also in the On Windows, with:
Original error: [vite-plugin-pwa:build] Expected '(', got 'string literal (object, 'object')'
file: /node_modules/.pnpm/lerc@3.0.0/node_modules/lerc/LercDecode.js:2314:10
2312: define([], function() { return Lerc; });/* jshint ignore:line */
2313: }
2314: else if (typeof module !== "undefined" && module.exports) {/* jshint ignore:line */
^
2315: //commonJS module 1.0/1.1/1.1.1 systems, such as nodeJS
2316: //http://wiki.commonjs.org/wiki/Modules
error during build:
RollupError: Expected '(', got 'string literal (object, 'object')'
at error (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at nodeConverters (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:2090:9)
at convertNode (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:975:12)
at convertProgram (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:966:48)
at parseAstAsync (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:2156:20)
at async Module.tryParseAsync (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:13490:21)
at async Module.setSource (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:13071:35)
at async ModuleLoader.addModuleSource (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:17713:13) Manually putting [vite-plugin-pwa:build] Expected ',', got 'e'
file: /node_modules/.pnpm/lerc@3.0.0/node_modules/lerc/LercDecode.js:2310:39
2310: console.log(">>><<< ", typeof module)
^
error during build:
RollupError: Expected ',', got 'e'
at error (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at nodeConverters (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:2090:9)
at convertNode (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:975:12)
at convertProgram (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:966:48)
at parseAstAsync (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/parseAst.js:2156:20)
at async Module.tryParseAsync (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:13490:21)
at async Module.setSource (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:13071:35)
at async ModuleLoader.addModuleSource (/node_modules/.pnpm/rollup@4.5.0/node_modules/rollup/dist/es/shared/node-entry.js:17713:13) As @GuichiZhao says, it doesn't happen in Vite v4.5, only in v5 Edit: If I remove |
Here's a minimal example to reproduce (involving only rollup 4.5.0, without vite): https://github.com/simon04/ol-rollup/tree/rollup-5258 |
It didn't reproduce in stackblitz but reproduced on my local Windows machine. The code after transformed by commonjs plugin was if (typeofundefinede === "function" &&undefinede.amd) {/* jshint ignore:line */
//amd loaders such as dojo and requireJS
//http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition
undefinede([], function() { return Lerc; });/* jshint ignore:line */
}
else if 'object'e !== "undefined" && module.exports) {/* jshint ignore:line */
//commonJS module 1.0/1.1/1.1.1 systems, such as nodeJS
//http://wiki.commonjs.org/wiki/Modules
module.exports = Lerc;/* jshint ignore:line */
}
else {
//assign to this, most likely window
this.Lerc = Lerc;
} I found that |
This issue has been resolved via #5268 as part of rollup@4.5.2. You can test it via |
Rollup Version
4.5.0
Operating System (or Browser)
Ubuntu 22.04.3 LTS
Node Version (if applicable)
v20.6.1
Link To Reproduction
https://vitejs.dev/
Expected Behaviour
Report
RollupError: Expected '(', got 'string literal (object, 'object')'
after upgrade vite 5, the error disappears after bringing back to vite 4, obviously there is something wrong with the rollup parser, it can not parse a legal syntax somehowelse if (typeof module !== "undefined" && module.exports)
should be a valid javascript syntaxActual Behaviour
Report error
The text was updated successfully, but these errors were encountered: