wagerfield / parallax

Parallax Engine that reacts to the orientation of a smart device
http://wagerfield.github.io/parallax/
Other
16.47k stars 2.14k forks source link

npm install doesn't seem to work when using `import` #318

Open nathan-i-martin opened 2 years ago

nathan-i-martin commented 2 years ago

Could not find a declaration file for module 'parallax-js'. 'C:/dev/premier-properties-management/node_modules/parallax-js/dist/parallax.js' implicitly has an 'any' type. Try 'npm i --save-dev @types/parallax-js' if it exists or add a new declaration (.d.ts) file containing 'declare module 'parallax-js';

This was the issue I received from Visual Studio Code while attempting to import a fresh npm install of Parallax. import Parallax from 'parallax-js'; I've since changed it to const Parallax = require('parallax-js'); which seems to work just fine.

I did also attempt to run the npm i --save-dev @types/parallax-js command however that didn't work out. I'm working in the Angular CLI environment (which includes babel), using typescript.

nathan-i-martin commented 2 years ago

I might be wrong, but I believe this might be an issue with parallax not being written in Typescript. I might fork and work on implementing that

reneroth commented 2 years ago

We'd appreciate that! I've meant to get more familiar with typescript for some time now, and this might be a good opportunity :)

nathan-i-martin commented 2 years ago

Absolutely! Let me give it a shot, I've forked and have a repo open over here: https://github.com/nmartin42/parallax-ts

nathan-i-martin commented 2 years ago

@reneroth I haven't tested, a bit busy and I also figured you probably have a better system for testing than I do. However, it seems as tho I've converted everything successfully! Please give it a shot and if you think it's good I can issue a merge request. Please also review my commits as I've made some changes here and there, which, if you don't like you may want to remove. For the most part everything is the same however.

reneroth commented 5 months ago

@nathan-i-martin thanks for the effort! I'd love to just keep this as a separate repository for now, since I (as you might've noticed sorry) barely have any time for stuff besides work and other grown up people things, so maintenance would be hard.

Would it be possible to only add the types definitions without changing the original JS file?

I am a bit confused though why it does not work by default, since I always assumed typescript was compatible with vanilla javascript?

nathan-i-martin commented 5 months ago

Hey! I wrote this a while ago and it also was incomplete so forgive me if my memory isn't totally accurate on the issue.

I also assumed the same thing. Maybe newer versions of TS work with it. Typescript is one of those things where it works when it works but if it doesn't, you're basically screwed haha

Theoretically tho someone should be able to import it as an "any" object and it would work. Like I said, it's been a minute since I've used parallax in a project so I'd have to test.