tcollinsworth / axios-cached-dns-resolve

Uses async dns.resolve instead of synchronous dns.lookup, optional cache, and periodic background refreshing
MIT License
39 stars 31 forks source link

my file is .mjs but I get the following #16

Closed BaptisteGarcin closed 3 years ago

BaptisteGarcin commented 3 years ago

I have the type module in package.json, node 14.15.5

import { registerInterceptor } from 'axios-cached-dns-resolve' ^^^^^^^^^^^^^^^^^^^ SyntaxError: Named export 'registerInterceptor' not found. The requested module 'axios-cached-dns-resolve' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using:...

I think I know why, it looks like npm is pulling version 3.0.0 while in your package.json I saw 2.0.3 and I set it to 2.0.3 and it now works

tcollinsworth commented 3 years ago

There are some latent issues that aren't yet solved with native esm/.mjs. Two that were deal breakers for me were newrelic and mocking don't work and, as of yet, there seem to be no solutions. I've been reverting my libraries from native esm. Anytime you see import, it's esm, but not necessarily native esm. The lib is still esm, just not native. The way my projects currently work is they require esm before this library. If you are using native esm, then try the following.

import axioCacheDnsResolve from 'axios-cached-dns-resolve'

const { registerInterceptor } = axioCacheDnsResolve
OperKH commented 2 years ago

There are some latent issues that aren't yet solved with native esm/.mjs. Two that were deal breakers for me were newrelic and mocking don't work and, as of yet, there seem to be no solutions. I've been reverting my libraries from native esm. Anytime you see import, it's esm, but not necessarily native esm. The lib is still esm, just not native. The way my projects currently work is they require esm before this library. If you are using native esm, then try the following.

import axioCacheDnsResolve from 'axios-cached-dns-resolve'

const { registerInterceptor } = axioCacheDnsResolve

With this code there is another error:

export {
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
 81ms

(node:4472) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
tcollinsworth commented 2 years ago

Which esm library are you using?

OperKH commented 2 years ago

Which esm library are you using?

It is on NodeJS 14 and 16