noisejs icon indicating copy to clipboard operation
noisejs copied to clipboard

Trouble importing

Open the-Kob opened this issue 3 years ago • 3 comments
trafficstars

https://stackoverflow.com/questions/70817415/having-trouble-importing-a-library-cannot-set-properties-of-undefined-setting

I'm trying to import this library to my project, but I'm having trouble doing so. It's true that I'm not doing it like it is said to be done on the git demo (doing the js directly in the html file), but my guess is that it should still work.

I have something like this:

import * as NOISE from "../libs/perlin.js";
//...
var y = Math.round(noise.perlin2(x, z)); //like they do in the git example

But I'm getting an error regarding the library itself:

Cannot set properties of undefined (setting 'noise')
    at noise.js:18
    at noise.js:310

(function(global){
  var module = global.noise = {}; /*18*/
  //...
  module.perlin2 = function(x, y) {
  //...
})(this); /*310*/

What am I doing wrong?

the-Kob avatar Jan 22 '22 22:01 the-Kob

Did you already find a solution for this problem?

GenieRobot avatar Mar 09 '22 17:03 GenieRobot

I have made a simple wrapper for this library with a class in typescript, feel free to use it: https://github.com/alanko0511/noisejs-typescript

alanko0511 avatar May 19 '22 07:05 alanko0511

@alanko0511, you are a life saver! 🙏

ada-ada-ada-art avatar Feb 21 '23 14:02 ada-ada-ada-art