Cannot import certain npm packages when using TypeScript
See original GitHub issueVersion
3.0.0-rc.10
Node and OS info
Node 8.10, yarn 1.9.2, macOS 10.13.6
Steps to reproduce
https://github.com/ffxsam/repro-import-bug
- Clone repo
- Run
yarn && yarn serve
- See critical error.
What is expected?
I expect the app to run with no issues.
What is actually happening?
Error is given: Cannot invoke an expression whose type lacks a call signature. Type ‘typeof moment’ has no compatible call signatures.
Using import moment from 'moment'
also does not work.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
npm module can't import - Stack Overflow
I'm the maintainer of pickr,. since version 1.4.5 there should be official type-declarations if you're using it within typescript.
Read more >Common TypeScript module problems and how to solve them
Enabling the compiler module resolution tracing in TypeScript can provide insight in diagnosing and solving problems.
Read more >Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >How To Use Modules in TypeScript | DigitalOcean
Modules are a way to organize your code into smaller, more manageable pieces, allowing programs to import code from different parts of the ......
Read more >module-not-found - Next.js
When importing a module from npm this module has to be installed locally. ... is a Node.js specific library that can't run in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This seems to be a bug in TypeScript, because per its documentation,
allowSyntheticDefaultImports
should betrue
by default whenesModuleInterop
istrue
.In this case, it only works properly when
allowSyntheticDefaultImports
is explicitly set totrue
.Note: Vue CLI simply scaffolds a standard usage for upstream deps like webpack and typescript, it doesn’t do any magic beyond the
tsconfig.json
in your project. In the future, please try to locate your issues in upstream tools first before opening an issue in Vue CLI.Some other imports require different syntax now. For instance, in a traditional JS project, this is fine:
In a TS project, it’s not:
This fix works for validator, but does not work for moment: