GithubHelp home page GithubHelp logo

Comments (5)

markcellus avatar markcellus commented on June 14, 2024 1

Thanks for filing issue! I'll need a little more information if that's okay: what's your Node version? Is your project a CommonJS module or ES module?

from scroll-js.

markcellus avatar markcellus commented on June 14, 2024 1

Hmm I'm not too familiar with how Vite resolves modules. But it looks like Vite is attempting to build scroll-js as a CommonJS module instead of ES module. scroll-js exposes multiple dist files that can be used, depending on how your project is set up.

See main and module fields here. If your project is an ES module, Vite should be resolving to the dist/scroll.js file in the module field instead of the dist/scroll.common.js file in the main field. (common.js extension just means it's meant for a CommonJS project)

Does that help at all? If not, I can try to pull Vite down and import it to see if I can reproduce.

from scroll-js.

moritzebeling avatar moritzebeling commented on June 14, 2024

Hey, thank you for taking the time and looking into it!
I’m taking the ES route and tested various node versions between 16.15.x and 18.4.x all throwing the same error.

The full error report looks like:

Cannot find module 'core-js/modules/es.object.to-string.js' imported from '[...]/node_modules/scroll-js/dist/scroll.common.js'
Error: Cannot find module 'core-js/modules/es.object.to-string.js' imported from '[...]/node_modules/scroll-js/dist/scroll.common.js'
    at viteResolve ([...]/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:50310:25)
    at Function.<anonymous> ([...]/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:50327:28)
    at Module._load (node:internal/modules/cjs/loader:787:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at [...]/node_modules/scroll-js/dist/scroll.common.js:10:83
    at Object.<anonymous> ([...]/node_modules/scroll-js/dist/scroll.common.js:13:3)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)

I am absolutely not sure, it can totally be a problem on my side, but yet again I did nothing more than importing the module... Are there any requirements?

from scroll-js.

markcellus avatar markcellus commented on June 14, 2024

Hey @moritzebeling just checking in. Hopefully you found a resolution for your issue. I'll leave this open for a few more days. If I don't hear back from you, I'll assume all is well and close issue. Thanks again for your contributions!

from scroll-js.

moritzebeling avatar moritzebeling commented on June 14, 2024

Hey Mark, thank you very much for checking back in. I was trying out several other plugins and now wanted to try yours once again because it seems to be one of the very few that support SSR and duration control :)

I tried with the "type": "module" and several Vite options but couldn’t solve the error.

When trying to import directly from the source file scroll-js/dist/scroll.js it said unexpected keyword "export", which I found very weird.

I then copied the file dist/scroll.js from the node_modules folder into my project and now import directly and funnily enough it now works:

import { scrollTo } from './scroll.js';

Unfortunately I don’t know enough about Vite, Rollup or CommonJS to really pinpoint how this could be resolved. It really only seems to be a configuration issue.

And I also know that this is not the idea of open source modules, but I will now use is as a temporary workaround. Thank you!

from scroll-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.