Typescript not finding 3rd party modules from 'node_modules' folder










1















I am working on a plain Typescript app and have successfully tested it with importing modules created by myself which are part of the project. Now I am trying to include a 3rd party module from 'node_modules'folder but the compiler is not able to find that module.



import * as pnp from '@pnp/pnpjs';


Below is my setting for tsconfig:




"compileOnSave": true,
"compilerOptions":
"types": ,
"sourceMap": true,
"module": "amd",
"target": "es5",
"noEmitOnError": true,
"outDir": "./dist"
,
"exclude": [
"node_modules",
"obj",
"bin"
]



Below is my package.json:




"version": "1.0.0",
"name": "OSD.SharePointHostedApp",
"private": true,
"devDependencies":
"@types/chai": "^4.1.7",
"@types/sharepoint": "^2013.1.6"
,
"dependencies":
"jquery": "^3.3.1",
"@pnp/pnpjs": "^1.2.5",
"chai": "^4.2.0"




Typescript Version: 1.0.3.0. (I tried updating to latest but it still shows 1.0.30.0, maybe coz of this??)



What am I missing here? I have checked and verified that the 3rd party module is present in the node_modules.



Update



There was a problem with the version. Even though I had installed latest version of typescript 3.1.6 it was not being picked up and old version 1.0.3.0 was shown. Somehow Typescript 1.0 was installed as part of Microsoft SDKs in the folder C:Program Files (x86)Microsoft SDKsTypeScript1.0 . I deleted that folder and now when I do tsc -v latest version number is shown-> 3.1.6 . But the original issue still remains










share|improve this question
























  • Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

    – Matt McCutchen
    Nov 13 '18 at 18:50











  • No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

    – Unnie
    Nov 13 '18 at 18:59
















1















I am working on a plain Typescript app and have successfully tested it with importing modules created by myself which are part of the project. Now I am trying to include a 3rd party module from 'node_modules'folder but the compiler is not able to find that module.



import * as pnp from '@pnp/pnpjs';


Below is my setting for tsconfig:




"compileOnSave": true,
"compilerOptions":
"types": ,
"sourceMap": true,
"module": "amd",
"target": "es5",
"noEmitOnError": true,
"outDir": "./dist"
,
"exclude": [
"node_modules",
"obj",
"bin"
]



Below is my package.json:




"version": "1.0.0",
"name": "OSD.SharePointHostedApp",
"private": true,
"devDependencies":
"@types/chai": "^4.1.7",
"@types/sharepoint": "^2013.1.6"
,
"dependencies":
"jquery": "^3.3.1",
"@pnp/pnpjs": "^1.2.5",
"chai": "^4.2.0"




Typescript Version: 1.0.3.0. (I tried updating to latest but it still shows 1.0.30.0, maybe coz of this??)



What am I missing here? I have checked and verified that the 3rd party module is present in the node_modules.



Update



There was a problem with the version. Even though I had installed latest version of typescript 3.1.6 it was not being picked up and old version 1.0.3.0 was shown. Somehow Typescript 1.0 was installed as part of Microsoft SDKs in the folder C:Program Files (x86)Microsoft SDKsTypeScript1.0 . I deleted that folder and now when I do tsc -v latest version number is shown-> 3.1.6 . But the original issue still remains










share|improve this question
























  • Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

    – Matt McCutchen
    Nov 13 '18 at 18:50











  • No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

    – Unnie
    Nov 13 '18 at 18:59














1












1








1


0






I am working on a plain Typescript app and have successfully tested it with importing modules created by myself which are part of the project. Now I am trying to include a 3rd party module from 'node_modules'folder but the compiler is not able to find that module.



import * as pnp from '@pnp/pnpjs';


Below is my setting for tsconfig:




"compileOnSave": true,
"compilerOptions":
"types": ,
"sourceMap": true,
"module": "amd",
"target": "es5",
"noEmitOnError": true,
"outDir": "./dist"
,
"exclude": [
"node_modules",
"obj",
"bin"
]



Below is my package.json:




"version": "1.0.0",
"name": "OSD.SharePointHostedApp",
"private": true,
"devDependencies":
"@types/chai": "^4.1.7",
"@types/sharepoint": "^2013.1.6"
,
"dependencies":
"jquery": "^3.3.1",
"@pnp/pnpjs": "^1.2.5",
"chai": "^4.2.0"




Typescript Version: 1.0.3.0. (I tried updating to latest but it still shows 1.0.30.0, maybe coz of this??)



What am I missing here? I have checked and verified that the 3rd party module is present in the node_modules.



Update



There was a problem with the version. Even though I had installed latest version of typescript 3.1.6 it was not being picked up and old version 1.0.3.0 was shown. Somehow Typescript 1.0 was installed as part of Microsoft SDKs in the folder C:Program Files (x86)Microsoft SDKsTypeScript1.0 . I deleted that folder and now when I do tsc -v latest version number is shown-> 3.1.6 . But the original issue still remains










share|improve this question
















I am working on a plain Typescript app and have successfully tested it with importing modules created by myself which are part of the project. Now I am trying to include a 3rd party module from 'node_modules'folder but the compiler is not able to find that module.



import * as pnp from '@pnp/pnpjs';


Below is my setting for tsconfig:




"compileOnSave": true,
"compilerOptions":
"types": ,
"sourceMap": true,
"module": "amd",
"target": "es5",
"noEmitOnError": true,
"outDir": "./dist"
,
"exclude": [
"node_modules",
"obj",
"bin"
]



Below is my package.json:




"version": "1.0.0",
"name": "OSD.SharePointHostedApp",
"private": true,
"devDependencies":
"@types/chai": "^4.1.7",
"@types/sharepoint": "^2013.1.6"
,
"dependencies":
"jquery": "^3.3.1",
"@pnp/pnpjs": "^1.2.5",
"chai": "^4.2.0"




Typescript Version: 1.0.3.0. (I tried updating to latest but it still shows 1.0.30.0, maybe coz of this??)



What am I missing here? I have checked and verified that the 3rd party module is present in the node_modules.



Update



There was a problem with the version. Even though I had installed latest version of typescript 3.1.6 it was not being picked up and old version 1.0.3.0 was shown. Somehow Typescript 1.0 was installed as part of Microsoft SDKs in the folder C:Program Files (x86)Microsoft SDKsTypeScript1.0 . I deleted that folder and now when I do tsc -v latest version number is shown-> 3.1.6 . But the original issue still remains







typescript node-modules






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 19:01







Unnie

















asked Nov 13 '18 at 18:02









UnnieUnnie

587316




587316












  • Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

    – Matt McCutchen
    Nov 13 '18 at 18:50











  • No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

    – Unnie
    Nov 13 '18 at 18:59


















  • Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

    – Matt McCutchen
    Nov 13 '18 at 18:50











  • No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

    – Unnie
    Nov 13 '18 at 18:59

















Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

– Matt McCutchen
Nov 13 '18 at 18:50





Is the original problem with importing the module solved? If not, please provide the code with the import so that we can try to reproduce the problem.

– Matt McCutchen
Nov 13 '18 at 18:50













No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

– Unnie
Nov 13 '18 at 18:59






No, when i write import statement it give me build error saying cannot find the module. I have updated my import statement and package.json to the question

– Unnie
Nov 13 '18 at 18:59













1 Answer
1






active

oldest

votes


















1














For TypeScript to look for modules under node_modules, the moduleResolution option has to be set to node. When the module option is set to amd, the default for moduleResolution is classic. (See the compiler options table.) Thus, you'll have to specify "moduleResolution": "node" in tsconfig.json.






share|improve this answer























  • Thanks it worked!

    – Unnie
    Dec 13 '18 at 18:16










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286997%2ftypescript-not-finding-3rd-party-modules-from-node-modules-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














For TypeScript to look for modules under node_modules, the moduleResolution option has to be set to node. When the module option is set to amd, the default for moduleResolution is classic. (See the compiler options table.) Thus, you'll have to specify "moduleResolution": "node" in tsconfig.json.






share|improve this answer























  • Thanks it worked!

    – Unnie
    Dec 13 '18 at 18:16















1














For TypeScript to look for modules under node_modules, the moduleResolution option has to be set to node. When the module option is set to amd, the default for moduleResolution is classic. (See the compiler options table.) Thus, you'll have to specify "moduleResolution": "node" in tsconfig.json.






share|improve this answer























  • Thanks it worked!

    – Unnie
    Dec 13 '18 at 18:16













1












1








1







For TypeScript to look for modules under node_modules, the moduleResolution option has to be set to node. When the module option is set to amd, the default for moduleResolution is classic. (See the compiler options table.) Thus, you'll have to specify "moduleResolution": "node" in tsconfig.json.






share|improve this answer













For TypeScript to look for modules under node_modules, the moduleResolution option has to be set to node. When the module option is set to amd, the default for moduleResolution is classic. (See the compiler options table.) Thus, you'll have to specify "moduleResolution": "node" in tsconfig.json.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 19:53









Matt McCutchenMatt McCutchen

13.5k819




13.5k819












  • Thanks it worked!

    – Unnie
    Dec 13 '18 at 18:16

















  • Thanks it worked!

    – Unnie
    Dec 13 '18 at 18:16
















Thanks it worked!

– Unnie
Dec 13 '18 at 18:16





Thanks it worked!

– Unnie
Dec 13 '18 at 18:16

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286997%2ftypescript-not-finding-3rd-party-modules-from-node-modules-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3