Use npm request module in Ionic 2 (third party libraries, Cannot find module "../package.json")


Hi, anybody tried to use the npm request module in typescript?

I’m in ionic2 RC3, I followed so I did:
npm install request --save npm install @types/request --save
In my .ts file I have:
import request from 'request';
And the error I’m getting is:
cookie.js:38Uncaught Error: Cannot find module "../package.json"(…)
That happens in this line (generated by the transpiler):
var __WEBPACK_IMPORTED_MODULE_4_request__ = __webpack_require__(1021);
The problem can be the collision with the Request type from @angular/http, but how can I avoid it?



I am facing the same issue. For my part if comes from the module googleapis which has the module tough-cookies as a dependency. I presume request also has that same dependency, as the error is the same: cookie.js:38 Uncaught Error: Cannot find module "../package.json"(…).

cookie.js:38 is var VERSION = require('../package.json').version;

My guess is that Ionic webpack does not bundle *.json… but I don’t know how to fix that, nor what the best approach is. Any help would be appreciated!


Finally figured it out, thanks to @rapropos 's comment on this thread here.

The issue was indeed related to webpack, and got fixed in this commit, which is included in v0.0.46. I was using @ionic/app-scripts v0.0.45.

To fix, simply run npm install @ionic/app-scripts@latest --save-dev.

Note however that there is currently a problem in v0.0.46 related to copying fonts (see issue 475 and 448), so you’ll need to manually copy them until the issue gets fixed.


Thanks a lot!!!

The commnad npm install @ionic/app-scripts@latest --save-dev worked!