Skip to content

Can not find local declaration file for scoped packages #23999

Closed

Description

@mlippert

I am using the noImplicitAny switch, but I'm not sure whether that matters other than not showing that the declaration file is not found as quickly. However I should be able to use the noImplicitAny switch by creating the required declaration file locally.

My testing seems to show that a local declaration file for a non-scoped package is found, but that one for a scoped package (@<scope>/name) is not.

The test sample I've attached uses the @feathersjs/express scoped package to demonstrate the issue.

Note that the feathersjs__express.d.ts file below does contain the declare module 'feathersjs__express'; as specified in the error message.

Also note that the contents of feathersjs__express.d.ts are basically identical to the contents of feathers-mongoose.d.ts which is correctly found (and when remove produces a similar TS7016 error.

TypeScript Version: 2.9.0-dev.20180506

Search Terms:
TS7016: Could not find a declaration file for module

Code

├── package.json
├── src
│   ├── feathersjs__express.d.ts
│   ├── feathers-mongoose.d.ts
│   └── index.ts
├── tsconfig.json

index.ts

import { express } from '@feathersjs/express';
import { service } from 'feathers-mongoose';

feathers-mongoose.d.ts

declare module 'feathers-mongoose'
{
    function init(options: string): any;

    namespace init
    {
        export let service: (options: string) => any;
    }

    export = init;
}

feathersjs__express.d.ts

declare module 'feathersjs__express'
{
    function feathersExpress(feathersApp: string): any;

    namespace feathersExpress
    {
        export let express: (feathersApp: string) => any;
    }

    export = feathersExpress;
}

Zip file containing the sources (as in the tree above)
ts_bug_src.zip

Expected behavior:
No errors

Actual behavior:

src/index.ts:1:25 - error TS7016: Could not find a declaration file for module '@feathersjs/express'. '/home/mjl/Projects/riff/test/node_modules/@feathersjs/express/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/feathersjs__express` if it exists or add a new declaration (.d.ts) file containing `declare module 'feathersjs__express';`

1 import { express } from '@feathersjs/express';
                          ~~~~~~~~~~~~~~~~~~~~~

Playground Link:

Related Issues:

Activity

  1. mhegazy commented on May 10, 2018

    @mhegazy
    Contributor

    the file name is irrelevant. in both files you are using declare module "..." { .. } form which is a global declaration..

    in the file feathersjs__express, you are saying to the compiler "I know a module exists, whose name is "feathersjs__express" and this is its type".

    the problem is you are not naming the module correctly, i.e. your module should look like:

    declare module '@feathersjs/express' {
        function init(options: string): any;
    
        namespace init {
            export let service: (options: string) => any;
        }
    
        export = init;
    }
  2. added
    Question
    on May 10, 2018
  3. mlippert commented on May 10, 2018

    @mlippert
    Author

    Mohamed Hegazy (@mhegazy) I believe that the file name is irrelevant, but then the error message is wrong, because I am naming the module exactly as specified by the error message (see above: add a new declaration (.d.ts) file containing 'declare module 'feathersjs__express';').

    And that did work (I thought I had tried using the name early on w/o success, but I probably had other issues at that time).

    Thanks, so I think this bug probably needs to be renamed to specify that the error message needs to be corrected.

  4. added
    Bug
    Domain: Error Messages
    and removed
    Question
    on May 10, 2018
  5. added this to the milestone on May 10, 2018
  6. mhegazy commented on May 10, 2018

    @mhegazy
    Contributor

    A PR to update the error message would be appreciated.

  7. mnpenner commented on Aug 1, 2018

    @mnpenner

    I just encountered this issue. Took me quite awhile to figure it out. Here's the Stackoverflow question I ended up creating because of it, and solution.

  8. mattmccutchen commented on Aug 1, 2018

    @mattmccutchen
    Contributor

    This should be an easy PR. I'm working on it.

  9. added a commit that references this issue on Aug 1, 2018
    d054621
  10. added
    Fixed
    on Aug 2, 2018
  11. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDomain: Error MessagesFixed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions