`Cannot find module` from a new owned TypeScript module

12,642

I downloaded the module and it looks like an issue with your build or publishing setup--the file lib/index.d.ts that typings points to doesn't exist in the published version.

├── LICENSE
├── README.md
├── data
│   └── jquery-3.4.1.js
├── lib
│   ├── src
│   │   ├── PJQuery.d.ts
│   │   ├── PJQuery.js
│   │   ├── index.d.ts
│   │   ├── index.js
│   │   ├── jQueryPlugin.d.ts
│   │   ├── jQueryPlugin.js
│   │   ├── setup.d.ts
│   │   └── setup.js
│   └── test
│       ├── basic.spec.d.ts
│       └── basic.spec.js
└── package.json
Share:
12,642
Uriel
Author by

Uriel

Updated on June 04, 2022

Comments

  • Uriel
    Uriel almost 2 years

    I have juste publish a new Typescript project on NPM registry, puppeteer-jquery. The code works fine. But when I try to use it in an other project:

    npm install puppeteer-jquery
    

    and try to import it with:

    import { PageEx, BrowserEx } from 'puppeteer-jquery';
    

    I get the error: Cannot find module 'puppeteer-jquery'.ts(2307)

    Locally, I can only use it by installing a local source copy, and importing:

    import { PageEx, BrowserEx } from './node_modules/puppeteer-jquery/src/setup';
    

    the package.json from pupeteer-jquery:

    {
      "name": "puppeteer-jquery",
      ...
      "main": "lib/index.js", /* also tried with "./lib/index.js" value */
      "typings": "lib/index.d.ts", /* tried with "types" and "typings" key */
      "devDependencies": {
        ...
        "typescript": "^3.6.4"
      },
      "files": ["lib", "data/*.js"] /* data contains jquery.js as a ressource */
    }
    
    

    the tsconfig.json from puppeteer-jquery:

    {
      "compilerOptions": {
        "target": "ES2017",
        "module": "commonjs",
        "declaration": true,
        "strict": true,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "outDir": "lib",
        "rootDirs": [
          "src"
        ]
      },
      "include": [ "src" ], /* added after the first post */
      "exclude": ["node_modules", "lib"]
    }
    

    npm publish --dry-run:

    npm notice 📦  [email protected]
    npm notice === Tarball Contents === 
    npm notice 1.1kB   LICENSE              
    npm notice 410B    lib/index.js         
    npm notice 280.4kB data/jquery-3.4.1.js 
    npm notice 5.7kB   lib/jQueryPlugin.js  
    npm notice 77B     lib/PJQuery.js       
    npm notice 1.0kB   lib/setup.js         
    npm notice 1.2kB   package.json         
    npm notice 2.0kB   README.md            
    npm notice 242B    lib/index.d.ts       
    npm notice 411B    lib/jQueryPlugin.d.ts
    npm notice 2.2kB   lib/PJQuery.d.ts     
    npm notice 518B    lib/setup.d.ts       
    npm notice === Tarball Details === 
    

    This issue looks like stackoverflow 54695891 but it's not the same.

    PS:

    • this is not my first Typescript project
    • this project have no depencences
    • I also try to include TS source and source maps into the released package, but withou more success.
    • Uriel
      Uriel over 4 years
      After lot of test, I rebuild a new project using this dependence and it's works.
    • Ivan Kaloyanov
      Ivan Kaloyanov almost 4 years
      In my case the issue was that I was missing "typeRoots": [ "./node_modules/@types" ] within the tsconfig.json file
  • Uriel
    Uriel over 4 years
    Strange, but your are right... let me fix that. and see if it's works.
  • Uriel
    Uriel over 4 years
    Fixed, but the issue is still the same with [email protected]
  • ecraig12345
    ecraig12345 over 4 years
    Is the tsconfig in your post the one from puppeteer-jquery or the consuming package?
  • Uriel
    Uriel over 4 years
    from pupeteer-jquery, I add direct link to github in the question.