axios: [ts] cannot find module 'axios'.
Summary
When I create a .ts
file and try to import axios it complains that it cannot find the module ‘axios’.
If I create a .js
file then it works fine.
As you can see the typings
file is in the package folder. Any ideas on why this is happening or what I need to do to make it work?
Context
- axios version: v0.17.1
- Environment: node v8.2.1, windows 10, typescript v2.6.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 19 (1 by maintainers)
try
"moduleResolution": "node"
in your tsconf.json It solved for meThanks
I notice this works when you have
module : "commonjs"
and does not work when you have module : esnext or es2015I wish I could fix this, if someone can help me. Thanks
The error remains after adding
"moduleResolution": "node"
totsconfig.json
. But disappeared after restarting VS Code.I got it working using this
import axios, { AxiosRequestConfig, AxiosPromise, AxiosResponse } from 'axios';
If anybody is still having issues with this, copying
node_modules/axios/index.d.ts
tonode_modules/@types/axios/index.d.ts
seemed to work for me.Or create a folder to hold your custom types and edit your tsconfig to include it.
Yarn
$ yarn add axios
npm
$ npm install axios --save
I’m having the same problem in Cloud9 without type script
const axios = require('axios')
Response { “errorMessage”: “Cannot find module ‘axios’”, “errorType”: “Error”, “stackTrace”: [ “Function.Module._load (module.js:417:25)”, “Module.require (module.js:497:17)”, “require (internal/module.js:20:19)”, “Object.<anonymous> (/var/task/getGroupHolesPlayed/index.js:4:15)”, “Module._compile (module.js:570:32)”, “Object.Module._extensions…js (module.js:579:10)”, “Module.load (module.js:487:32)”, “tryModuleLoad (module.js:446:12)”, “Function.Module._load (module.js:438:3)” ] }