Typescript bundling result contains unresolvable `*/node_modules/tslib/*` imports
Author: gdlmxCreated Aug 3, 2025Updated Mar 19, 2026
Labelst¹ 🐞 bugt⁸ ⋅ triage
Rollup Version
4.46.2
Operating System (or Browser)
ubuntu
Node Version (if applicable)
No response
Link To Reproduction
https://stackblitz.com/edit/rollup-repro-gzxyv94l
Expected Behaviour
When using preserveModules: true in a TypeScript project, all dependency should be resolvable in the output bundle.
Actual Behaviour
The output bundle contains lots of unresolvable tslib imports, such as:
import { __awaiter } from '../node_modules/tslib/tslib.es6.js';
import { __rest } from '../node_modules/tslib/tslib.es6.js';The relative path ../node_modules/tslib doesn't exist in the output dir.
If you add external: [/node_modules/] to rollup.config.js, the import path will be absolute, such as /home/user/xxx/.../node_modules/tslib/....
Config to Reproduction
// rollup.config.js
import typescript from '@rollup/plugin-typescript';
export default {
input: 'src/main.ts',
output: {
dir: 'dist',
format: 'es',
preserveModules: true, // This setting triggers the bug
},
plugins: [typescript()],
};
// tsconfig.json
{
"compilerOptions": { "target": "es6" }
}How to bypass this bug
Copy the node_modules/tslib folder into dist manually.
Related issue
Source: rollup/rollup