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

rollup-rewriter doesn't handle unknown deps well #688

Closed
tivac opened this issue Nov 21, 2019 · 1 comment · Fixed by #749
Closed

rollup-rewriter doesn't handle unknown deps well #688

tivac opened this issue Nov 21, 2019 · 1 comment · Fixed by #749

Comments

@tivac
Copy link
Owner

tivac commented Nov 21, 2019

Expected Behavior

When dealing with unknown dependencies, @modular-css/rollup-rewriter should cleanly handle them without exploding.

Current Behavior

🔥

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
@sveltejs/svelte-virtual-list (imported by thing.svelte)
[!] (plugin @modular-css/rollup-rewriter) TypeError: Cannot destructure property `assets` of 'undefined' or 'null'.
TypeError: Cannot destructure property `assets` of 'undefined' or 'null'.
    at css.reduce (c:\project\node_modules\@modular-css\rollup-rewriter\rewriter.js:100:55)
    at Array.reduce (<anonymous>)
    at entries.forEach (c:\project\node_modules\@modular-css\rollup-rewriter\rewriter.js:99:23)
    at Map.forEach (<anonymous>)
    at Object.generateBundle (c:\project\node_modules\@modular-css\rollup-rewriter\rewriter.js:68:21)
    at Promise.resolve.then (c:\project\node_modules\rollup\dist\rollup.js:16621:25)

Error is coming from this chunk of code

].reduce((out, curr) => {
const { assets = [] } = chunks[curr];
assets.forEach((asset) => out.add(asset));
return out;
}, new Set());

Possible Solution

A conditional early-out before the destructuring would solve that.

const css = [
    ...graph.dependenciesOf(file),
    ...(file in chunks ? chunks[file].imports : []),
    file,
].reduce((out, curr) => {
+   if(!chunks[curr]) {
+       return out;
+   }
+
    const { assets = [] } = chunks[curr];

    assets.forEach((asset) => out.add(asset));

    return out;
}, new Set());
@tivac
Copy link
Owner Author

tivac commented Apr 21, 2020

This is released in @modular-css/rollup-rewriter@25.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant