amplify-js: Could not find TypeScript declaration for '../vendor/paho-mqtt'

If you are using TypeScript and you try to install the latest version of aws-amplify you will see the following error:

/Users/username/WebstormProjects/my-project/node_modules/@aws-amplify/pubsub/lib/Providers/MqttOverWSProvider.d.ts
(1,23): Could not find a declaration file for module '../vendor/paho-mqtt'. '/Users/username/WebstormProjects/my-project/node_modules/@aws-amplify/pubsub/lib/vendor/paho-mqtt.js' implicitly has an 'any' type.
  Try `npm install @types/aws-amplify__pubsub` if it exists or add a new declaration (.d.ts) file containing `declare module 'aws-amplify__pubsub';`

Trying to install@types/aws-amplify__pubsub doesnt help as it doesnt exist so the solution is to declare it yourself.

To Reproduce

  1. Error happens when starting up (npm start) a Create React App TypeScript project

Expected behavior No loading errors

Desktop (please complete the following information):

  • OS: OSX
  • Browser: n/a
  • Version: n/a

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

  • A temporary fix, working for us:

    npm install @types/paho-mqtt --save-dev
    

    Update your tsconfig.json:

    +  "files": [
    +    "./node_modules/@types/paho-mqtt/index.d.ts"
    +   ]
    

Same issue with

"amazon-cognito-identity-js": "3.2.0",
"aws-amplify": "1.2.4",
"aws-amplify-react-native": "2.2.3",
"react": "16.8.1",
"react-native": "0.61.3",

error: bundling failed: Error: Unable to resolve module ../vendor/paho-mqtt from node_modules/@aws-amplify/pubsub/lib/Providers/MqttOverWSProvider.js:

None of these files exist:

  • node_modules/@aws-amplify/pubsub/lib/vendor/paho-mqtt(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  • node_modules/@aws-amplify/pubsub/lib/vendor/paho-mqtt/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)

After discussing with a colleague of mine we came up with a workaround to solve the problem. I believe this problem relates to https://github.com/Microsoft/TypeScript/issues/15031. Work around:

  1. Install @typs/paho-mqtt for types. npm install -D @types/paho-mqtt
  2. create a global.d.ts if you haven’t already.
  3. Add code below this to global.d.ts
declare module '*/vendor/paho-mqtt' {
  export { Client } from 'paho-mqtt';
}

@chris-ramon Thanks for adding the temporary fix and @elorzafe picking up this ticket.

This is happening on both of the latest versions:

  • 1.1.3
  • 1.1.4-unstable.2