Skip to content
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

preserveModules creates a _tslib.js and _tslib.js.map files in _virtual folder #240

Closed
cyclops24 opened this issue Aug 14, 2020 · 4 comments
Labels
kind: question This is a usage or similar question kind: support Asking for support with something or a specific use case problem: removed issue template OP removed the issue template without good cause problem: stale Issue has not been responded to in some time solution: Rollup behavior This is Rollup's behavior and not specific to this plugin solution: workaround available There is a workaround available for this issue

Comments

@cyclops24
Copy link

cyclops24 commented Aug 14, 2020

What happens and why it is wrong

The build process creates two files for me like this:

build/_virtual/_tslib.js
build/_virtual/_tslib.js.map

How I can remove this? Why we need these files?

Environment

Versions

  • typescript: 3.7.2
  • rollup: 1.27.4
  • rollup-plugin-typescript2: 0.27.0

rollup.config.js

// ...
typescript({ useTsconfigDeclarationDir: true }),
// ...

tsconfig.json

{
  "compilerOptions": {
    "rootDir": "src",
    "declaration": true,
    "declarationDir": "build",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom", "es2016", "es2017"],
    "sourceMap": true,
    "jsx": "react",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*", "types/images.d.ts"],
  "exclude": [
    "node_modules",
    "build",
    "storybook-static",
    "src/**/stories.tsx",
    "src/**/*.stories.tsx",
    "src/**/*.test.tsx"
  ]
}

package.json

plugin output with verbosity 3

@cyclops24
Copy link
Author

Maybe related to this: #170

@agilgur5 agilgur5 added problem: no repro No reproduction was provided (and have not tried to repro without one) problem: removed issue template OP removed the issue template without good cause labels Apr 24, 2022
@agilgur5
Copy link
Collaborator

Per #170 it sounds like this only happens with preserveModules, but you didn't include a full Rollup config in order to confirm that.
It also sounds like it may be necessary per that PR as rpt2 uses tslib, but I'm not 100% sure.

I'm also curious if this still happens with Rollup v2

@agilgur5 agilgur5 added problem: needs more info This issue needs more information in order to handle it and removed problem: no repro No reproduction was provided (and have not tried to repro without one) labels Apr 26, 2022
@agilgur5
Copy link
Collaborator

Seems like #282 reproduced this

@agilgur5 agilgur5 changed the title The build process create a _tslib.js and _tslib.js.map files in _virtual folder preserveModules creates a _tslib.js and _tslib.js.map files in _virtual folder Jun 11, 2022
@agilgur5 agilgur5 added the problem: stale Issue has not been responded to in some time label Sep 4, 2022
@agilgur5
Copy link
Collaborator

I created a reproduction for this issue here. Per my comments there, the _virtual dir will only be created if you're using preserveModules and are using tslib helpers (e.g. you're using syntax that isn't natively supported by the target you've specified in your tsconfig.json, similar to @babel/runtime. I specifically used async while targeting ES2015 in the repro).

This is necessary for how preserveModules works in Rollup, as "all exports are rewritten in a way that does not depend on Node's dependency resolution algorithm". tslib is resolved as a virtual module in rpt2 so that it can be used without knowledge of Node's resolution algorithm (i.e. without @rollup/plugin-node-resolve).

If you don't want this _virtual dir with preserveModules and don't want tslib helpers in your output, you can either:

  1. target a higher version of ECMAScript OR
  2. don't use unsupported syntax OR
  3. add @rollup/plugin-node-resolve which will resolve tslib through node_modules
    • this option is commented out in the repro above, for reference

@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case solution: Rollup behavior This is Rollup's behavior and not specific to this plugin kind: question This is a usage or similar question solution: workaround available There is a workaround available for this issue and removed problem: needs more info This issue needs more information in order to handle it labels Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question This is a usage or similar question kind: support Asking for support with something or a specific use case problem: removed issue template OP removed the issue template without good cause problem: stale Issue has not been responded to in some time solution: Rollup behavior This is Rollup's behavior and not specific to this plugin solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

No branches or pull requests

2 participants