Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import with Vite #60

Closed
micah-redwood opened this issue May 8, 2023 · 2 comments
Closed

Unable to import with Vite #60

micah-redwood opened this issue May 8, 2023 · 2 comments

Comments

@micah-redwood
Copy link

Hey, first off thanks for writing this super helpful and concise library.

Unfortunately, after an npm install, I'm unable to get it to work when running 'vite build' on a standard Vite project. Here's the error message:

Error: Cannot find module '/.../node_modules/limited-cache/dist/core/defaultOptions' imported from /.../node_modules/limited-cache/dist/index.js
   at new NodeError (node:internal/errors:393:5)
   at finalizeResolution (node:internal/modules/esm/resolve:323:11)
   at moduleResolve (node:internal/modules/esm/resolve:916:10)
   at defaultResolve (node:internal/modules/esm/resolve:1124:11)
   at nextResolve (node:internal/modules/esm/loader:163:28)
   at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
   at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
   at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
   at link (node:internal/modules/esm/module_job:75:36) {
 code: 'ERR_MODULE_NOT_FOUND'
}

I was able to fix this by adding .js to the exports in limited-cache/dist/index.js, e.g.

export * from './core/defaultOptions.js';
export * from './core/LimitedCache.js';
export * from './core/LimitedCacheObject.js';
export * from './core/limitedCacheUtil.js';
export * from './core/lowLevelFunctions.js';
export * from './types.js';
//# sourceMappingURL=index.js.map

But then get a similar error for the next import, e.g.

Error: Cannot find module '/.../node_modules/limited-cache/dist/core/lowLevelFunctions' imported from /.../node_modules/limited-cache/dist/core/LimitedCache.js
...

For now I'm just compiling the export I need using this service, but it would be awesome if the npm build worked out of the box.
https://bundlejs.com/?q=limited-cache&treeshake=%5B%7BLimitedCacheObject%7D%5D&config=%7B%22analysis%22%3Aundefined%7D

Thanks

@spautz
Copy link
Owner

spautz commented May 8, 2023

Whoops, sorry about that. I'll get this updated and released after hours today

@spautz spautz closed this as completed in 2f2f679 May 9, 2023
@spautz
Copy link
Owner

spautz commented May 9, 2023

Accidentally auto-closed this a little early, but this should now be fixed with v2.1.1

spautz added a commit to spautz/package-template that referenced this issue May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants