'Can I import from node_modules of a module?
I'm not that great at JS/TS but I'm helping run a build system. I have a bit of code that was submitted, and I'm not sure if I should alter the build system or kick it back to the developer.
The code looks like this...
import * as googleAuth from "googleapis/node_modules/google-auth-library"
When I run yarn install the various modules are installed properly in ./node_modules/ including googleapis and google-auth-library. When I run yarn build I get something like this:
yarn run v1.19.1
$ rm -rf lib; ./node_modules/.bin/tsc -d -p tsconfig.npm.json
Error: src/foo/bar/common/oauth_helper.ts(3,29): error TS[23]: Cannot find module 'googleapis/node_modules/google-auth-library' or its corresponding type declarations.
When I test this out locally, I can make the error go away by doing cd ./node_modules/googleapis && yarn install but that installs a second set of all the modules needed there.
Is there something that I'm missing or should I tell the developer that he needs to import directly from goggle-auth-library. Furthermore if the developer is referencing this module explicitly I feel like he should list it as a dependency in package.json, not get it implicitly.
Solution 1:[1]
I would suggest to directly install google-auth-library instead of going through the node_modules of another package.
This might be risky because lets says in future googleapis package updates and for some reason removes dependency on google-auth-library this will break your app.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shivam |
