-
Notifications
You must be signed in to change notification settings - Fork 32
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
SyntaxError: Unexpected token 'export' #37
Comments
You have to load the esm or esm-wallaby library before loading this library
or use native ESM in your project with type: 'module' or via a .mjs file.
…On Fri, Jun 16, 2023 at 2:38 PM J9B10 ***@***.***> wrote:
Hello
I have a script that makes many axios requests and it causes errors like
(AxiosError: getaddrinfo EAI_AGAIN) due to many DNS requests.
Then I saw on the internet that I could use this
"axios-cached-dns-resolve" module to cache DNS in axios.
But whenever I implement the code and run my script it returns the error:
\axios-cached-dns-resolve\index.js:1
export {
^^^^^^
SyntaxError: Unexpected token 'export'
I do not understand where is the fault.
It looks like the official help page is confusing with import examples.
My script does not accept importation because it is a single script like
"myscript.js" where I put all the code to be executed.
In myscript.js
I had to comment out "//import" as my execution returns the error:
import { registerInterceptor } from 'axios-cached-dns-resolve'
^^^^^^
SyntaxError: Cannot use import statement outside a module Instead of
"import" I used "const":
const { registerInterceptor } = require("axios-cached-dns-resolve");
Still I get the error:
SyntaxError: Unexpected token 'export'
It seems to me that the module is broken or I am doing something wrong.
I need help.
My example code: myscript.js
//import { registerInterceptor } from 'axios-cached-dns-resolve'
const { registerInterceptor } = require("axios-cached-dns-resolve");
const axiosClient = axios.create(config);
function func_01(a, b, c) {
url = https://domain.com;
//axios
registerInterceptor(axiosClient)
.get(url)
// ... mais código aqui ... //
}
------------------------------
- Note: This is just an abbreviated piece of code.
Because it's fine and it's functional and there's no need to post all
the code.
- The only problem and the implementation of
"axios-cached-dns-resolve".
Please someone help me to solve this.
—
Reply to this email directly, view it on GitHub
<#37>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFYANOY3D6SJW2WHZPNVZDXLSRZRANCNFSM6AAAAAAZJTIOAU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I have identified the problem. Actually I needed to convert all my script to ESM. I had difficulty converting due to lack of information, but through a lot of research I was able to convert to ESM. I put the and then I converted all exports and imports following https://reflectoring.io/nodejs-modules-imports/. Now my script is a Nodejs ESM. |
Glad you got it working. That was one way and probably the best because many libraries are going native ESM. This library isn't native esm yet, so you could have just loaded the esm or esm-wallaby library (wallaby if I used optional chaining) before loading this library and it would have worked without changing the type or renaming all files from .js to .mjs. |
Hello
I have a script that makes many axios requests and it causes errors like
AxiosError: getaddrinfo EAI_AGAIN
due to many DNS requests.Then I saw on the internet that I could use this
axios-cached-dns-resolve
module to cache DNS in axios.But whenever I implement the code and run my script it returns the error:
I do not understand where is the fault.
It looks like the official help page is confusing with import examples.
My script does not accept importation because it is a single script like
myscript.js
where I put all the code to be executed.In
myscript.js
I avoided using the
//import
as my execution returns the error:Instead of
import
I usedconst
:const { registerInterceptor } = require("axios-cached-dns-resolve");
Still I get the error:
It seems to me that the module is broken or I am doing something wrong.
I need help.
My example code:
myscript.js
Because it's fine and it's functional and there's no need to post all the code.
axios-cached-dns-resolve
.node_modules
.Please someone help me to solve this.
The text was updated successfully, but these errors were encountered: