question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import error "cannot find module"

See original GitHub issue

Hi, 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.js imported 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:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
markcelluscommented, Jun 28, 2022

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.

1reaction
markcelluscommented, Jun 28, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found