Import error "cannot find module"
See original GitHub issueHi, when I try to import your module
import { scrollTo, scrollIntoView } from 'scroll-js';
I get the following error:
Cannot find module
core-js/modules/es.object.to-string.jsimported from./node_modules/scroll-js/dist/scroll.common.js
I have no idea what this could mean… Any idea how I could get this to work? Thank you in advance.
PS: I am using Vite with SvelteKit if that‘s of any help
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Module Import error - cannot find module
I was trying to import the module dynamically in ES6 on Meteor application. But getting an error cannot find module. The same import...
Read more >Error [ERR_MODULE_NOT_FOUND]: Cannot find module ...
The "Error [ERR_MODULE_NOT_FOUND]: Cannot find module" occurs when you set the type attribute to module in your package.json file, but omit the file...
Read more >Error: cannot find module [Node npm Error Solved]
you're trying to import an item from a module you don't have installed in your project directory; you're importing some things from an...
Read more >How to fix npm cannot find module error
The cannot find module error occurs because npm cannot find the module required by the index.js file. In this case, the axios module....
Read more >How to resolve "Cannot find module" error in Node
The issue is that Node is unable to find the module that you are trying to import into your Node application. The most...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
mainandmodulefields here. If your project is an ES module, Vite should be resolving to thedist/scroll.jsfile in themodulefield instead of thedist/scroll.common.jsfile in themainfield. (common.jsextension 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.
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?