Typescript axios cannot find

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

TS-Check: cannot find module #28233

TS-Check: cannot find module #28233

Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Domain: TSServer Issues related to the TSServer

Comments

TypeScript Version: 3.1.3

//@ts-check const  axios > = require('axios')

Expected behavior:
Axios will be required from ‘./node_modules/axios/index’

Actual behavior:
Error shown is cannot find module ‘axios’ despite axios being installed. Note that this problem is not axios specific, it occurs with any module. However, if I use the following syntax then it is required correctly.

//@ts-check const  axios > = require('./node_modules/axios/index')

Screenshots:

screenshot 2018-10-30 at 16 17 51

screenshot 2018-10-30 at 16 18 21

screenshot 2018-10-30 at 16 19 56

The text was updated successfully, but these errors were encountered:

Here’s the contents of my jsconfig.json file in the project root

< "compilerOptions": < "target": "ES6", "lib": ["es5", "es6", "es7"] > >

However, having tested again with the jsconfig.json file deleted, it still produces the same error. Although, in some projects on my system the module will be required fine. I should also note — just in case it makes any difference — that this bug is occuring within vscode 1.28.2

@andy-ms So i’ve been testing, and I’ve found something else which is strange

The project is laid out like this:

project subprojectA folderA index.js node_modules folderB . subprojectB . jsconfig.json 

If i have the project folder open in vscode and open subprojectA/folderA/index.js , then the error will be thrown. However, if I open the folderA directly in vscode, then the module will be required correctly.

Could the issue be related to the fact that there are so many subProject folders whose child folders also contain node_modules?

RyanCavanaugh removed the Needs Investigation This issue needs a team member to investigate its status. label Mar 7, 2019

@NileDaley Does this issue still happen for you? I can try to reproduce it, but it would help me a lot to have the actual project that’s failing. If you can share that some way I can sign an NDA if that would help.

This was a long time ago, and I don’t experience the issue anymore as we’re now using typescript instead of js + tscheck.

As far as I can remember, the issue was caused by having the jsconfig.json file in the wrong folder. I had it at the root of the project, whereas it needed to be further down in the tree.

From my example above, it needed to change to

project subprojectA folderA index.js node_modules jsconfig.json folderB . subprojectB 

So it actually couldn’t find the module because there is no node_modules at the root level where the jsconfig.json was.

I’m having the same issue on some packages inside node_modules (writing javascript, not typescript). Some of them work just fine, but some throw ts check errors.

For example the screenfull package is throwing the ‘cannot find module’ error.
Looking inside node_modules/screenfull/dist/screenfull.js there is a self-executing function which ends like this:

if (isCommonjs)  module.exports = screenfull; > else  window.screenfull = screenfull; >

Using Webpack 4 to import the module. Everything is working fine in the website output.

Also it looks like jsconfig path-aliases are ignored (here modules is an alias for node_modules as set the same in Webpack as an alias, so Webpack knows modules is an alias for node_modules , as well as vs code knows by its jsconfig.json paths):

require('modules/prismjs/plugins/keep-markup/prism-keep-markup.js');

Could it be @ts-check doesn’t work well while using Webpack imports/requires?

@sandersn I’m also having this issue, not with @ts-check , but by writing TS. A project I’m having issues with is https://gitlab.com/runtimesharks/runtimesharks.com. Current problems: http and react-dom/server , but if I yarn add axios , it will complain about that one too. Adding @types/node doesn’t help, either.

I have a feeling it’s my lack of experience that’s causing this and I’m missing something obvious and/or configured something wrong, anticipated apologies if so 😞

Edit: never mind me, I had «noResolve»: true 🤦🏻‍♂️.

I encountered this when setting target: «esnext» in my jsconfig.js file. one of the culprits is the tmp-promise module. it seems that regular js files become unparseable?

@wmertens @Friksel can you open separate issues with specific repros please?

Found similar issue when switching to VS Code / JSdoc / @ts-check with JS / ES6 as a lightweight alternative to TypeScript, for type-checking.

If I put jsconfig.js in /project instead of /project/js , then there is no problem with using absolute paths, e.g. import SomeData from ‘js/Data/SomeData.js’ (note the lack of a leading slash).

If I put jsconfig.js in /project/js instead, then I cannot use that absolute path style, and must use relative paths instead to make things work, else I get the (2307) error mentioned here.

May be obvious to some, but I don’t like the suggestion on the VS Code documentation that you should place the file in e.g. /project/js by default, or at least they should explain the problems this can cause.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

[ts] cannot find module ‘axios’. #1221

[ts] cannot find module ‘axios’. #1221

Comments

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.

image

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?

The text was updated successfully, but these errors were encountered:

I notice this works when you have
module : «commonjs»
and does not work when you have module : esnext or es2015

I wish I could fix this, if someone can help me.
Thanks

try «moduleResolution»: «node» in your tsconf.json
It solved for me

Same error here. It is not «tsconf.json» but «tsconfig.json». The suggested moduleResolution change did not fix it for me.

This fixed the problem for me as well. Any idea what’s the logic behind the solution.

Closing due to solution provided by @gs-akhan. For further questions regarding this I would recommend StackOverflow or a Typescript forum/community.

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. (/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)»
]
>

@gs-akhan ‘s solution did not work for me, still receiving «Cannot find module ‘axios'» type error

Module not found: Can’t resolve ‘axios’ in ‘C:\Users\Mubarak M Aminu\Desktop\ReactClass\Blog\src’
any solution to this problem

Источник

Cannot find module axios typescript code example

Solution 1: Ok — tried a few things from a fresh install, and here is what I got to work: //tsconfig.json //app.controller.ts I then ran Solution 2: Looking at the Nexmo package on Github, I see here that it is exporting a default value from its main module: https://github.com/Nexmo/nexmo-node/blob/master/src/Nexmo.js#L175 This means in your typescript file you should be able to simply say: Some packages in npm are not commonjs friendly (meaning they are not node js module friendly) and in that case you would need to import that in typescript using this syntax: Give that first one a shot though and see if it works for you. So you need to create a folder that will have a package.json file with the dependency Then add the layer in the functions from AWS UI, left side menu Then add the layer to your function Now, by doing the above activity the issue will be resolved and Axios dependency is added successfully individually to the microservice.

Runtime.ImportModuleError Error: Cannot find module ‘axios/lib/utils’ Serverless

I found the fixes for this. when we call third-party API from our Lambda it requires the Axios to be implemented internally. So you need to create a folder that will have a package.json file with the dependency

Steps to Add layer

Then add the layer in the functions from AWS UI, left side menu

Added layer to the function

Then add the layer to your function

Now, by doing the above activity the issue will be resolved and Axios dependency is added successfully individually to the microservice.

Cannot find module typescript config Code Example, Web# NPM Installation Method npm install —global typescript # Global installation npm install —save-dev typescript # Local installation #Yarn Installation …

Typescript 2.0 Cannot Find Module

You need to tell vscode to use it. Please setup tssdk more

More

Also try tsc on the command line. If its an error on the command line then its an error in vscode and you need to double check the code . share the tsconfig.json / project on github etc 🌹

Cannot find module ‘typescript’ angular 9 Code Example, WebGet code examples like «cannot find module . Grepper. Follow. GREPPER; SEARCH SNIPPETS; PRICING; FAQ; All Languages >> Html >> cannot find …

How can I use the included Axios Type definitions for dependency injection in TypeScript

It is because you are not importing AxiosInstance interface.

Cannot find module ‘typescript’ in angular Code Example, Web# NPM Installation Method npm install —global typescript # Global installation npm install —save-dev typescript # Local installation #Yarn Installation …

Error: Cannot find module ‘nexmo’ & error TS2307: Cannot find module nexmo

Ok — tried a few things from a fresh install, and here is what I got to work:

import < Controller, Get >from '@nestjs/common'; import < AppService >from './app.service'; import Nexmo from 'nexmo'; const nexmo = new Nexmo(< apiKey: '', apiSecret: '', >); @Controller() export class AppController < constructor(private readonly appService: AppService) <>@Get() getHello(): string < console.log(nexmo.verify); return this.appService.getHello(); >> 
~/G/A/test-nest> master > nest build ~/G/A/test-nest >master >node ./dist/main [Nest] 21347 - 08/19/2020, 11:36:27 AM [NestFactory] Starting Nest application. [Nest] 21347 - 08/19/2020, 11:36:27 AM [InstanceLoader] AppModule dependencies initialized +18ms [Nest] 21347 - 08/19/2020, 11:36:27 AM [RoutesResolver] AppController <>: +7ms [Nest] 21347 - 08/19/2020, 11:36:27 AM [RouterExplorer] Mapped route +3ms [Nest] 21347 - 08/19/2020, 11:36:27 AM [NestApplication] Nest application successfully started +3ms 

Looking at the Nexmo package on Github, I see here that it is exporting a default value from its main module: https://github.com/Nexmo/nexmo-node/blob/master/src/Nexmo.js#L175

This means in your typescript file you should be able to simply say:

Some packages in npm are not commonjs friendly (meaning they are not node js module friendly) and in that case you would need to import that in typescript using this syntax:

import Nexmo = require('nexmo'); 

Give that first one a shot though and see if it works for you.

Reactjs — typescript: Cannot find module ‘react’, Web01/12/2016· If you have installed @types/react and it still doesn’t work, I recommend that you use a recent version of Typescript and then close your …

Источник

Читайте также:  Python tkinter label примеры
Оцените статью