error importing axios in typescript script folder

Post Reply
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

error importing axios in typescript script folder

Post by bkromer »

I have created a script folder with typescript support.
When I try to import axios like

Code: Select all

import axios from 'axios';
Switch gives me this error:
require() of ES Module C:\Users\Administrator\Documents\Skripte\App\node_modules\axios\index.js from C:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js not supported. Instead change the require of index.js in C:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js to a dynamic import() which is available in all CommonJS modules.
If I change the import to

Code: Select all

import {axios} from 'axios'; 
typescript cant find it.
I installed axios with

Code: Select all

 npm i --save axios
and the folder is in node_modules. I know the default export of axios has the same name "axios".
I dont get any errors by transpiling. Iam completely lost here.... really unproductiv day so far.

Freddy please help. :( Would you? :?:
Benjamin
User avatar
foxpalace
Member
Posts: 33
Joined: Fri Jan 14, 2011 12:25 pm
Location: Germany

Re: error importing axios in typescript script folder

Post by foxpalace »

yes freddy, i have the same errors with other modules - on one mac no problem, other mac problem
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: error importing axios in typescript script folder

Post by freddyp »

Are these new scripts or old scripts? Check if you have a tsconfig.json file in the script folder. If not, create a new script folder and copy the tsconfig.json from there and see if it solves the problem.
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: error importing axios in typescript script folder

Post by bkromer »

freddyp wrote: Thu Oct 06, 2022 8:43 am Are these new scripts or old scripts? Check if you have a tsconfig.json file in the script folder. If not, create a new script folder and copy the tsconfig.json from there and see if it solves the problem.
Its a completely new created script folder with typescript option checked. It has the tsconfig.json.

tsconfig.json:

Code: Select all

{
  "compilerOptions": {
	"target" : "ES2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true
  },
  "files": [
    "main.ts"
  ]
}
Benjamin
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: error importing axios in typescript script folder

Post by freddyp »

What version of axios are you using (check package.json)?
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: error importing axios in typescript script folder

Post by bkromer »

freddyp wrote: Thu Oct 06, 2022 11:21 am What version of axios are you using (check package.json)?

Code: Select all

 ... "dependencies": {
        "axios": "^1.0.0"
}...
Thats the newest.
I uninstalled it and forced the installation of axios@0.27.2 and it worked right away. I am going to try newer versions step by step I just saw in a old script that I had this version. Therfore I picked this Version 0.27.2.

Which Version do you have running?

Thanks for the support.
Benjamin
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: error importing axios in typescript script folder

Post by freddyp »

I tried it out now as well and I have the same problem. I have used Axios successfully already several times, so I tried the previous version (0.26.0) and that one works fine. The way to install a specific version from npm:

Code: Select all

npm i axios@0.26.0
On npm you can see that axios was updated 2 days ago so they must have made a change that causes this problem.

With the flexibility of being able to use thousands of packages comes the burden of finding the right package and also the right version of the package. Frustrating sometimes.
Post Reply