3

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 SDKs\TypeScript\1.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

2
  • 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. Commented Nov 13, 2018 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 Commented Nov 13, 2018 at 18:59

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.