jhurliman / node-rate-limiter

A generic rate limiter for node.js. Useful for API clients, web crawling, or other tasks that need to be throttled
MIT License
1.5k stars 132 forks source link

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/limiter/dist/esm/RateLimiter' #73

Closed tracycollins closed 3 years ago

tracycollins commented 3 years ago

Not sure if this is a case of "pilot error" but after upgrading this package and switching to 'import' from 'require' in my code, I'm getting the following error (when I try to run my tests with mocha):

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Volumes/RAID1/projects/threeceeUtilities/node_modules/limiter/dist/esm/RateLimiter' imported from /Volumes/RAID1/projects/threeceeUtilities/node_modules/limiter/dist/esm/index.js at finalizeResolution (internal/modules/esm/resolve.js:276:11) at moduleResolve (internal/modules/esm/resolve.js:699:10) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11) at Loader.resolve (internal/modules/esm/loader.js:86:40) at Loader.getModuleJob (internal/modules/esm/loader.js:230:28) at ModuleWrap. (internal/modules/esm/module_job.js:56:40) at link (internal/modules/esm/module_job.js:55:36)

I'm importing as in the README:

import { RateLimiter } from "limiter";

I've added the most recent version (limiter@2.0.0) using 'yarn add limiter'

Am I doing something wrong? Any help appreciated

richardsimko commented 3 years ago

I have the same problem. The issue is that node requires all import statements to have a .js at the end. The way this project is transpiled doesn't work with Node ESM.

jhurliman commented 3 years ago

@richardsimko thanks for catching that. Let me get a fix together.

jhurliman commented 3 years ago

https://github.com/jhurliman/node-rate-limiter/pull/74

jhurliman commented 3 years ago

This PR fails because jest (using babel) can no longer resolve the import paths (see https://travis-ci.org/github/jhurliman/node-rate-limiter/jobs/769026954). I'm searching for a solution that will work for both Node ESM and Jest+Babel.

jhurliman commented 3 years ago

I added a transform step during compilation to append .js to imports. This should be fixed now, please let me know if you run into issues. 2.0.1 has been published.

tracycollins commented 3 years ago

Works for me. Thanks!