-
Notifications
You must be signed in to change notification settings - Fork 699
Labels
on hold: awaiting more feedbackWaiting for more users' feedback to decide the next actionWaiting for more users' feedback to decide the next actionp3: nice to have / edge casesame as rollup
Description
Reproduction link or steps
For cjs code spliting build of following code:
main1.js,main2.js(use two entries to create shared chunk)
import { throwError } from "./shared.js"
throwError();shared.js
export function throwError() {
console.log("=== 'this' inside 'throwError'===")
console.log(this)
console.log("=== Error.stack from 'throwError' ===")
console.log(new Error("DEMO_STACKS").stack);
}Rolldown produces:
// dist/main1.cjs
const require_shared = require('./shared.cjs');
require_shared.throwError();where require_shared.throwError call has require_shared object as this context.
What is expected?
works like original esm code
$ node src/main1.js
=== 'this' inside 'throwError'===
undefined
=== Error.stack from 'throwError' ===
Error: DEMO_STACKS
at throwError (file:///xxx/src/shared.js:6:15)What is actually happening?
$ node dist/main1.cjs
== 'this' inside 'throwError'===
{ throwError: [Getter] }
=== Error.stack from 'throwError' ===
Error: DEMO_STACKS
at Object.throwError (/xxx/dist/shared.cjs:8:14)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.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
rolldown: 0.15.0-snapshot-64a831c-20241207003504 => 0.15.0-snapshot-64a831c-20241207003504Any additional comments?
I was looking at webpack's output had a bunch of (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs) and I remembered the trick (0,...) is for avoiding this context. Vite SSR recently added this too vitejs/vite#18748
This may be not a big deal especially when users are explicitly choosing cjs build. I just found rollup doesn't handle this either rollup repl.
But, this might be relatively important for app format since users are not explicitly saying cjs in this case and rolldown needs to emulate esm as much as possible.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
on hold: awaiting more feedbackWaiting for more users' feedback to decide the next actionWaiting for more users' feedback to decide the next actionp3: nice to have / edge casesame as rollup