aws-sdk-js: Typescript error: Cannot find name 'Buffer'/'http'/'https'
Hi!
First, I want to thank you for this SDK, it will be very useful for us!
I have some errors when building the javascript bundle for my application (React/Typescript/Webpack). It seems to work anyway (or maybe I have not used it enough yet), but I am not comfortable building our app with errors đ.
Here is an extract of the errors:
Hash: 6824b5df64cd8f5d85c3
Version: webpack 1.14.0
Time: 4139ms
Asset Size Chunks Chunk Names
frontend.js 3.63 MB 0 [emitted] main
frontend.js.map 5.28 MB 0 [emitted] main
+ 617 hidden modules
ERROR in /Users/rmarenco/Dev/taiga/frontend/node_modules/aws-sdk/clients/wafregional.d.ts
(416,39): error TS2304: Cannot find name 'Buffer'.
...
ERROR in /Users/rmarenco/Dev/taiga/frontend/node_modules/aws-sdk/lib/config.d.ts
(1,34): error TS2307: Cannot find module 'http'.
ERROR in /Users/rmarenco/Dev/taiga/frontend/node_modules/aws-sdk/lib/config.d.ts
(2,35): error TS2307: Cannot find module 'https'.
And you can find the full errors on this gist => https://gist.github.com/remimarenco/c51c3170fbfd8d548e6fd2fe4542cdb1
I am also including my configuration files in the gist, in case they could be useful đ. The architecture of my application is like this:
taiga/
- frontend/
- node_modules/ <= All my frontend dependencies
- src/ <= All my .tsx
package.json
- node_modules/ <= All my backend and dev dependencies
- taiga2/
- static/ <= Folder where webpack store the outputs
package.json
tsconfig.json
webpack.config.js
Do you think you know what is not correct in my configuration? Or is it on the sdk side + webpack (and/or typescript)?
Thanks a lot!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 36 (6 by maintainers)
@pvamshi So, I was able to reproduce your issue. You actually need to add
"types": ["node"]
to thetsconfig.app.json
file that the angular-cli creates in thesrc
directory. By default,types
is an empty array.Based on these TypeScript docs:
Since
types
is empty, it is excluding thenode
typings that you installed vianpm install @types/node
.I had the same issue as @pvamshi. @chrisradekâs solution
tsconfig.app.json
worked for me, but because that file extends../tsconfig.json
you can also just delete"types": ["node"]
if you followed his previous instructions re:tsconfig.json
. Thanks for all your hard work troubleshooting this.@remimarenco TypeScript is complaining because some node environment types are needed. This is a limitation for now that we might be able to get around by stubbing those interfaces in the future.
I admit itâs odd to have to include node typings for a front-end project, but can you try installing the environment typings to see if it gets around your issue?
npm install --save-dev @types/node
Updated tsconfig.app.json inside src folder, it works for me, thanks!
I found a work-around, I have to dig deeper to see if the issue is related to just
ts-loader
or not.In your
tsconfig.json
file, you can add"types": ["node"]
as one of yourcompilerOptions
. Then, also make sure to install@types/node
at the same level as yourtsconfig.json
file. If I followed your gist correctly, that would be your top-levelpackage.json
, the one thatâs a sibling of yourtsconfig.json
file.I have same problem. I am using angular-cli stable with Angular 4. I added
"types":["node"],
but the problem still exists. Any help is appreciated.I also had to add
After changing tsconfig.app.json, it worked for me. Changing tsconfig.json hasnât solved this issue.
Based on the last comments, it sounds like this issue is resolved: there are some Angular-specific hurdles to using the dependent
@types/node
module, but with appropriate configuration everything works as expected.Please let me know if Iâm mistaken and thereâs something more the SDK should be doing here.
For anybody using the ionic framework, and wanting to use the aws-sdk with typings. Its a bit different than what explained above:
npm install --save-dev @types/node
npm uninstall --save-dev @types/node
then you should be able to build if you still get errors, go into the typings file you just copied and clear the errors, there should be a reference import on line 30, that you can comment out, and on line 2381: class URL says its duplicate, just rename it, and URLSearchParams below.
Hi @MissAnichka, did you have this error message: ERROR in /Users/j/Projects/commercial/node_modules/aws-amplify/lib/PubSub/Providers/MqttOverWSProvider.d.ts (1,23): Cannot find type definition file for âpaho-mqttâ.
EDIT: fix is
npm i âsave-dev @types/zen-observable
npm i âsave-dev @types/paho-mqtt
It doesnât make any sense, but on Ionic you have to add this, even if it doesnât make sense. under compiler options
I was able to make it work by taking out the types key in
tsconfig.app.json
. Putting back in the empty list made it fail again, so it seems like the non-existence of that key also will fix the issue.This worked for me as well. May I suggest, you could add this as an official step to take in the README.md. Based on the feedback here, it seems to help anyone adding aws-sdk to an angular-cli based project.