Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve module error when importing from package with only type definitions #408

Closed
thw0rted opened this issue Oct 5, 2020 · 3 comments · Fixed by #437 · 4 remaining pull requests
Closed

Unable to resolve module error when importing from package with only type definitions #408

thw0rted opened this issue Oct 5, 2020 · 3 comments · Fixed by #437 · 4 remaining pull requests

Comments

@thw0rted
Copy link

thw0rted commented Oct 5, 2020

I use the NPM package @esri/arcgis-rest-types in a project, and I'm trying to hook up Karma testing using this plugin. It's notable because this package contains no runtime code at all, only .d.ts typings. When my code imports one of the types from this package, I get the message ERROR [karma-server]: Error: Unable to resolve module [@esri/arcgis-rest-types] from {source file path}.

I put together a simple reproduction. Clone and npm install, then npm run build and npm run start -- you should see some simple console output. Note that the emitted code does not include any references to the Esri package, since it only contains type information. Now, run npm run test, and you should see the aforementioned message.

The way I see it, one of three things is happening here:

  1. I have my project configured wrong for what I'm trying to do, in which case I'd appreciate any pointers, or
  2. The way Esri has packaged these types to distribute via NPM is wrong -- bad package.json or something? -- and for some reason the Typescript language service and Webpack are both happy to use them anyway, while this plugin (correctly) fails, or
  3. This is a bug in the plugin , and it can't handle "empty" packages like this one correctly

If it helps, I can try to find other similar packages that export types only, but aren't in the @types namespace and aren't meant to be used in an ambient context.

@07akioni
Copy link
Contributor

@erikbarke Could you please have a look at the issue? Thanks a lot. I've met the same problem.

It can be reproduced in https://github.com/monounity/karma-typescript/tree/master/examples/typescript-latest

Just run npm i csstype and add import { Properties } from 'csstype' at the 2nd line of src/hello.component.ts then the error happens.

23 02 2021 23:28:33.962:ERROR [karma-server]: UncaughtException: Error: Unable to resolve module [csstype] from [/Users/hrsonion/Development/Dev2021/karma-typescript/examples/typescript-latest/src/hello.component.js]

@thw0rted
Copy link
Author

thw0rted commented Mar 2, 2021

Thanks @07akioni for figuring it out and @erikbarke for the merge! Is there an easy way to tell when this shows up on NPM?

@erikbarke
Copy link
Collaborator

@thw0rted, @07akioni, v5.5.0 is on npm now 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment