zsoltc / worley-noise

Worley noise in JavaScript.
MIT License
37 stars 4 forks source link

bundled code in npm package fails in Node #5

Closed derhuerst closed 5 years ago

derhuerst commented 5 years ago

I can't use worley-noise@2.0.0 with Node, because

It would be cool to be able to use the package in Node 6 without further steps. One solution would be to babel-transpile the src code into dist and expose a bundle in addition.

derhuerst commented 5 years ago

Let me know if you want a PR for this.

zsoltc commented 5 years ago

Hey @derhuerst , Thanks for the feedback. I'm a bit confused. Webpack produces UMD builds so it should be usable in Node as well. Do you have any info on this? Feel free to open a PR if you have a good solution for this. Thanks.

derhuerst commented 5 years ago

True, indeed it's not related to the bundling itself (although I still think it would be good to have transpiled, unbundled code in the npm package as well), but to Webpack. After a quick search, I found https://github.com/webpack/webpack/issues/6522#issuecomment-366704672 .

zsoltc commented 5 years ago

Thanks for the link. I made the change and it seems to work. Hopefully won't break any other environment. Published new npm package version (2.0.1). Please check when you have some time.

derhuerst commented 5 years ago

Now I get this:

> algorithmic-vomit@0.1.1 test /home/travis/build/derhuerst/algorithmic-vomit
> ./cli.js worley
cWkacnQmjGHCUfdtdEqTDMEWymRWlLjaNiiooaZGmDPWTKdGrcIaPYHHyZPTNpLweaTtsZOasyJFoCJqJwebpack://WorleyNoise/./src/worley-noise.js?:127
        this._points[minIdx].selected = true;
                                      ^
TypeError: Cannot set property 'selected' of undefined
    at WorleyNoise._calculateValue (webpack://WorleyNoise/./src/worley-noise.js?:127:39)
    at WorleyNoise.getManhattan (webpack://WorleyNoise/./src/worley-noise.js?:52:19)
    at worley (/home/travis/build/derhuerst/algorithmic-vomit/cli.js:19:42)
    at color (/home/travis/build/derhuerst/algorithmic-vomit/index.js:14:34)
    at fill (/home/travis/build/derhuerst/algorithmic-vomit/index.js:25:14)
    at Object.<anonymous> (/home/travis/build/derhuerst/algorithmic-vomit/cli.js:28:26)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
zsoltc commented 5 years ago

I've looked at your code. The cause of the problem is an API change. The getManhattan function now expects an object with x and y property. It's updated in the readme. worley.getManhattan({ x: x/40, y: y/45 }, 2) should work.

derhuerst commented 5 years ago

Thanks!