Skip to content

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

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

Open
1 of 2 tasks
cruzdanilo opened this issue Sep 26, 2024 · 5 comments
Open
1 of 2 tasks
Labels
bug Something isn't working

Comments

@cruzdanilo
Copy link

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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

  • I'm interested in working on this issue

Compensating engineering work financially will speed up resolution

  • I'm willing to offer financial support
@cruzdanilo cruzdanilo added the bug Something isn't working label Sep 26, 2024
@privatenumber
Copy link
Owner

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
Copy link
Author

@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
Copy link
Owner

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
Copy link
Author

cruzdanilo commented Sep 27, 2024

some findings:

  • it runs from a temp dir, ex: /home/runner/setup-pnpm/node_modules/.bin/store/v3/tmp/_tmp_1899_624633c3449ae285a3524f3806c80932
  • the working dir is the library root, but it doesn't have a .git dir
  • github's locale is C.UTF-8 instead of the usual en_US.UTF-8, which causes file sorting to be different

@nta
Copy link

nta commented Feb 21, 2025

This seems to happen as a result of the path in this scenario containing node_modules, leading to rollup-plugin-dts not emitting any file and therefore returning the unprocessed input.

The order-dependent behavior here is likely due to the program cache in the plugin:

https://github.com/Swatinem/rollup-plugin-dts/blob/deddf70ccc09345f41b3129004ce3321b0529a54/src/index.ts#L45

... i.e. if a file that imports the 'broken' module gets processed first, the compiler context contains an entry for the file with 'isExternalLibraryImport' set inside the TS compiler.

When testing this, if instead of reusing the object containing the rollup-plugin-dts instance here, I comment out the following line:

configs.dts = config;

... my project (which was affected by this, for it being a git module dependency as opposed to a published package) compiles fine.

The plugin seems to have been changed in this regard since the last release, too - however merely bumping it doesn't fix this issue because the path around isEntry needs a check over there as well and bumping to the latest commit there instead of the 6.1.1 tag fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants