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.

code splitting broken on Windows

See original GitHub issue

What happens and why it is wrong

Briefly: Code splitting is not supported now

Versions

  • typescript: 3.5.3
  • rollup: 1.20.3
  • rollup-plugin-typescript2: 0.24.0

rollup.config.js

import resolve from 'rollup-plugin-node-resolve';
import ts2 from 'rollup-plugin-typescript2';

export default {
  // NOTE: object here
  input: {
    'my-lib': 'src/main.ts',
    'my-tools': 'src/tools.ts'
  },
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    resolve(),
    ts2()
  ]
};

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "sourceMap": true,
    "importHelpers": true,
    "downlevelIteration": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,

    "lib": ["esnext"],
    "types": ["node"]
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

files

src/tools.ts

export function myFn() {
    console.log('Hello World!');
}

src/main.ts

import { myFn } from './tools';

console.log(myFn());

plugin output

dist/my-tools.js OK

function myFn() {
    console.log('Hello World!');
}

export { myFn };

dist/my-lib.js WRONG

function myFn() {
    console.log('Hello World!');
}

console.log(myFn());

expected output

dist/my-lib.js

import { myFn } from './my-tools.js';

console.log(myFn());

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ezolenkocommented, Sep 5, 2019

I see the problem, rollup doesn’t normalize paths when using them as keys for code splitting. Workaround is to add rollupCommonJSResolveHack: true to rpt2 options (solves a similar problem with another plugin, they fixed it in recent release actually).

I’ll open rollup bug.

1reaction
ezolenkocommented, Nov 14, 2019

@igisev can you use rollupCommonJSResolveHack: true as a workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack code splitting not working as intended #397 - GitHub
Webpack code splitting not working as intended #397 ... I checked the source code, and the plugin is properly exporting different modules.
Read more >
Browser extension is not working with code-splitting
However clicking the browser action icon do nothing. No error messages will show up in background script. No login window or popup will...
Read more >
Code Splitting - webpack
Code splitting is one of the most compelling features of webpack. This feature allows you to split your code into various bundles which...
Read more >
Tree shaking and code splitting in webpack - LogRocket Blog
Here, we'll explain tree shaking and code splitting in webpack and discuss how to combine them for the most optimal bundle possible.
Read more >
How to fix ChunkLoadError in your ReactJS application
If you use code splitting and dynamic imports, old code can cause this issue. Here's how to fix it in React.lazy() with a...
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