privatenumber / pkgroll

📦 Zero-config package bundler for Node.js + TypeScript
MIT License
1.17k stars 28 forks source link

🐛 `PARSE_ERROR` on type export when building inside a pnpm script on github #92

Open cruzdanilo opened 2 weeks ago

cruzdanilo commented 2 weeks ago

Problem

the issue only happens in a very specific case:

error:

Error [RollupError]: src/Foo.ts (1:15): Expression expected (Note that you need plugins to import files that are not JavaScript)
    at Object.getRollupError (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/parseAst.js:282:41)
    ... 4 lines matching cause stack trace ...
    at async ModuleLoader.addModuleSource (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:20163:13) {
  cause: Error [RollupError]: Expression expected
      at Object.getRollupError (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/parseAst.js:282:41)
      at ParseError.initialise (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:14107:40)
      at convertNode (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:15717:10)
      at convertProgram (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:15061:12)
      at Module.setSource (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:16679:24)
      at async ModuleLoader.addModuleSource (/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/node_modules/.pnpm/rollup@4.22.4/node_modules/rollup/dist/shared/rollup.js:20163:13) {
    code: 'PARSE_ERROR',
    pos: 15
  },
  code: 'PARSE_ERROR',
  id: '/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/src/Foo.ts',
  pos: 15,
  loc: {
    column: 15,
    file: '/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/src/Foo.ts',
    line: 1
  },
  frame: '1: export default interface Foo {}\n                  ^',
  watchFiles: [
    '/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/src/index.ts',
    '/home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1799_ec9c655ee68917aa8e2862cfd73c8666/src/Foo.ts'
  ],
  [Symbol(augmented)]: true
}

seems like the file is being interpreted as javascript. the error doesn't happen in multiple machines i tried (macos and linux)

Expected behavior

no error

Minimal reproduction URL

https://github.com/cruzdanilo/repro-pkgroll-ci/actions/runs/11057662251/job/30721965511

Version

v2.5.0

Node.js version

v22.9.0

Package manager

pnpm

Operating system

Linux

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

privatenumber commented 2 weeks ago

Interesting use-case.

I'm thinking it doesn't work because pkgroll expects it to be executed when the CWD is the root of the project.

Feel free to submit a PR!

cruzdanilo commented 2 weeks ago

@privatenumber sure. i will check the actual cwd, but how would it affect ts vs js? it is also weird that it doesn't happen in other environments.

privatenumber commented 2 weeks ago

Not sure—I was just speculating since I think that's a pretty big assumption I made when I was developing it. Please investigate and report back if you can

cruzdanilo commented 2 weeks ago

some findings: