PepsRyuu / nollup

Rollup compatible development bundler for fast rebuilds and HMR.
MIT License
488 stars 28 forks source link

Error: Unknown object type "set iterator" #70

Closed geocine closed 4 years ago

geocine commented 4 years ago

I have a working setup with rollup and typescript. I just added nollup and changed my dev setup to this

rimraf public && cross-env NODE_ENV=development nollup -c --hot --content-base public

I get this error which I really don't understand.

ParseError: ndex.js
Error: Unknown object type "set iterator"
    at bundle (/workspace/phaser3-rollup-typescript/node_modules/nollup/lib/index.js:508:15)
    at async generateImpl (/workspace/phaser3-rollup-typescript/node_modules/nollup/lib/index.js:693:21)

You may test by running yarn dev command here. I have the repository here:

PepsRyuu commented 4 years ago

That's really strange. Looking into it further, it looks like rollup-plugin-typescript2 is the culprit here. It's for some reason, checking all of the plugins in the Rollup config.

When Nollup instantiates plugins, it creates a private __context property. The plugin API uses this context to allow plugins to do their work. __context contains a property called moduleIds (a property that plugins can access). This is implemented using Set.

image

This is something I can introduce a fix for, just need to hide __context. I will also look into trying to get plugins to emit their stack trace for easier debugging. I'll try to get back to you as soon as possible on this one.

On a side note, I do recommend reporting an issue with the maintainer of the plugin though, as it should understand object properties that are using Sets. Seems like it could potentially cause similar issues in the future for other projects.

PepsRyuu commented 4 years ago

Released nollup@0.10.7 that removes the private property which allows the TypeScript plugin to succeed.

I noticed a couple of problems with your config though. First one is phaser. The package wasn't distributed properly, points to a source directory instead of a compiled module. So it's failing to find require imports, and it would add significant compilation time considering how big it is. Easiest solution is to use rollup-plugin-alias and add an alias for phaser:

alias({
      entries: [{
        find:'phaser', 
        replacement: path.resolve(process.cwd(), 'node_modules/phaser/dist/phaser.js')
      }]
    }),

You also are using the rollup-plugin-copy plugin during development, which is going to cause infinite loops because of the watching feature. Development mode should rarely be copying files, everything should really be done in memory so that it improves performance. Also it messes up the folder hierarchy and you had to start adding very specific gitignore rules.

Rule of thumb I like to follow:

Better error handling will come when I have more time to look into it. :)

geocine commented 4 years ago

@PepsRyuu thank you for taking the time to look into this. I was able to make my setup run without phaser. However with phaser I am still encountering an issue:

ParseError: node_modules/phaser/src/polyfills.js
Error: ENOENT: no such file or directory, open '/workspace/phaser3-rollup-typescript/node_modules/phaser/src/polyfills.js'
    at parse (/workspace/phaser3-rollup-typescript/node_modules/nollup/lib/index.js:114:23)

This could be a phaser related issue as you pointed out that it was not properly distributed. I will try to figure this out on my own but would appreciate if you could point me in the right direction.

PepsRyuu commented 4 years ago

That's why I suggested using rollup-plugin-alias so you can bypass that. :)

geocine commented 4 years ago

I have updated code here with the @rollup/plugin-alias it shows that error.

https://github.com/geocine/phaser3-rollup-typescript/tree/nollup

geocine commented 4 years ago

I switched things up a bit, removed rollup-plugin-node-resolve and rollup-plugin-commonjs on development mode. It finally worked.

https://github.com/geocine/phaser3-rollup-typescript/tree/nollup

It compiles everytime I change my source files eg. Game.ts , however it doesn't reload the module. I have to reload my browser. Any additional things I need to look into?

PepsRyuu commented 4 years ago

There's no hook into module.hot.accept. This needs to be added. Typically frameworks provide support for HMR, but it looks like phaser3 does not. You can add the following code snippet if you want to hot reload instead of hot module:

module.hot.accept(() => window.location.reload());

Note, you need to update your build config to exclude this line of code in production, otherwise your production build will break. Examples directory has examples that demonstrate this.

PepsRyuu commented 4 years ago

I'll add a section to the documentation to clarify this as it's not very clear about this step. 🙂

geocine commented 4 years ago

@PepsRyuu Thank you that definitely works 👍

PepsRyuu commented 4 years ago

No problem! Added a section in the documentation to describe this: https://github.com/PepsRyuu/nollup#adding-hot-support-to-app