question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS files outside project dir not being parsed -- `microbundle` uses outdated version of rpt2

See original GitHub issue

What happens and why it is wrong

Environment

TS files outside the project directory being parsed as Flow files instead of TS

SyntaxError: /absolute/path/to/file.ts: Support for the experimental syntax 'flow' isn't currently enabled (2:8):

I am experiencing this when using microbundle to bundle my monorepo projects/packages

Original issue: https://github.com/developit/microbundle/issues/808

Repro: https://github.com/icaro-capobianco/bundle-bug-repro

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
icaro-capobiancocommented, Jun 2, 2022

Thank you so much @agilgur5, you inspired me today! Hope to collaborate again in the future.

1reaction
agilgur5commented, May 27, 2022

Got it to work

Can see my fork and read through the detailed commit log to understand it, but I’ll summarize here too.

microbundle uses an outdated version of rpt2

microbundle is using an older version of rpt2 from ~1.5 years ago, 0.29.0. Notably, 0.30.0 updated the @rollup/pluginutils dep to v4, which contains a breaking change in https://github.com/rollup/plugins/pull/517. With that change to filter, it now resolves files outside of the cwd.

I’ll report downstream to the microbundle folks that they should probably update to fix some issues like these.

empty chunk

With the pnpm override added, rpt2 resolves the file correctly and there is no error anymore… but it produces an empty chunk! But rpt2 does actually transform the code properly; here’s the output of some logs I added on this line 🤔 :

rpt2: transformResult: '{"code":"export * from 'bundle-bug-repro/modules/code';\r\n","map":{"mappings":""}}'

That was pretty perplexing for a while, but it turns out that’s actually correct behavior though because Rollup applies treeshaking and the export does nothing. This is because export * from ... actually doesn’t include the default export, and hence it is empty and treeshaken. I changed this to export { default } from ... and then it outputs a correct non-empty file 😉

workaround in older rpt2 exists too, setting rootDir

The older rpt2 that microbundle uses has a workaround for this too, using rootDir as was implemented in #249. I confirmed that this works in your repo when you add "rootDir": "../../" to some-package’s tsconfig.json.

Notably, in my last comment I couldn’t get this to work for some reason… but that’s actually because I made a coding error while modifying the local rpt2 😅 (I didn’t add braces to a previously one-line conditional when I added logging to it and completely broke the transform hook as such). Project references don’t quite work in this version, but I think that’s because https://github.com/rollup/plugins/pull/517 fixes absolute paths as well, so that’s probably due to the older version too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

microbundle | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
microbundle-crl - npm Package Health Analysis - Snyk
Ensure you're using the healthiest npm packages. Snyk scans all the packages in your projects for vulnerabilities and provides automated fix advice.
Read more >
visual studio - Typescript error "Cannot write file ... because it ...
In my instance, I was using the outDir option but not excluding the destination directory from the inputs: // Bad { "compileOnSave": true ......
Read more >
microbundle - Bountysource
I'm trying to bundle a React component library. I'm using Typescript and CSS Modules. When I try to build (or watch for that...
Read more >
unknown compiler option jsximportsource - TechKnowByte
The current TS version is not aware of the new @jsxImportSource and thus it ... The command dotnet build invokes the F# compiler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found