`Cannot call a namespace` error with rpt2 but not `tsc`
See original GitHub issueWhat happens and why it is wrong
When I run tsc -p .
on my project, everything compiles as expected, but when I use rollup
and rollup-plugin-typescript2
with minimal config, it gives me a TypeScript error. I am using the same TypeScript version in both cases as revealed by using tsc -v
at the terminal and also checking with verbosity: 3
.
You can see a repro here.
Please note that I am using a fork of Rollup in there which fixed a sourcemap issue that actually allows me to see the underlying TypeScript problem.
The TypeScript error is just a random error with the qrcode-generator
NPM package, it says Cannot call a namespace, but the usage should be fine.
Environment
- Windows 10
- Rollup fork, see above
Versions
- typescript:
tsc -v
=Version 2.7.2
but I also have a dev dependency on TypeScript 2.7.2 - rollup:
adrianheine/rollup#sourcemap
see above - rollup-plugin-typescript2:
0.11.1
rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
export default {
input: 'index.ts',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
resolve(),
typescript()
]
};
tsconfig.json
{
"compilerOptions": {
}
}
package.json
{
"name": "rollup",
"version": "1.0.0",
"main": "bundle.js",
"repository": "https://gitlab.com/TomasHubelbauer/bloggo-rollup.git",
"author": "Tomáš Hübelbauer <tomas@hubelbauer.net>",
"license": "MIT",
"scripts": {
"start": "node node_modules/rollup/bin/rollup -c"
},
"devDependencies": {
"rollup": "adrianheine/rollup#sourcemap",
"rollup-plugin-node-resolve": "^3.0.3",
"rollup-plugin-typescript2": "^0.11.1",
"tslint": "^5.9.1",
"typescript": "^2.7.2"
},
"dependencies": {
"jsqr": "^1.0.2",
"qrcode-generator": "^1.3.1"
}
}
plugin output with verbosity 3
rpt2: typescript version: 2.7.2
rpt2: rollup-plugin-typescript2 version: 0.11.1
rpt2: plugin options:
{
"verbosity": 3,
"check": true,
"clean": false,
"cacheRoot": "C:\\Users\\Tom\\Desktop\\bloggo-rollup/.rpt2_cache",
"include": [
"*.ts+(|x)",
"**/*.ts+(|x)"
],
"exclude": [
"*.d.ts",
"**/*.d.ts"
],
"abortOnError": true,
"rollupCommonJSResolveHack": false,
"typescript": "version 2.7.2",
"useTsconfigDeclarationDir": false,
"tsconfigOverride": {},
"tsconfigDefaults": {}
}
rpt2: rollup config:
{
"input": "index.ts",
"plugins": [
{
"name": "node-resolve"
},
{
"name": "rpt2"
}
],
"entry": "index.ts",
"external": [
"",
""
]
}
rpt2: built-in options overrides: {
"module": 5,
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"outDir": "C:\\Users\\Tom\\Desktop\\bloggo-rollup",
"moduleResolution": 2,
"declarationDir": null
}
rpt2: parsed tsconfig: {
"options": {
"module": 5,
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"outDir": "C:\\Users\\Tom\\Desktop\\bloggo-rollup",
"moduleResolution": 2,
"declarationDir": null,
"configFilePath": "C:\\Users\\Tom\\Desktop\\bloggo-rollup/tsconfig.json"
},
"fileNames": [
"C:/Users/Tom/Desktop/bloggo-rollup/index.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"compilerOptions": {}
},
"errors": [],
"wildcardDirectories": {
"c:/users/tom/desktop/bloggo-rollup": 1
},
"compileOnSave": false,
"configFileSpecs": {
"includeSpecs": [
"**/*"
],
"validatedIncludeSpecs": [
"**/*"
],
"wildcardDirectories": {
"c:/users/tom/desktop/bloggo-rollup": 1
}
}
}
rpt2: included:
'[
"*.ts+(|x)",
"**/*.ts+(|x)"
]'
rpt2: excluded:
'[
"*.d.ts",
"**/*.d.ts"
]'
rpt2: Ambient types:
rpt2: transpiling 'C:\Users\Tom\Desktop\bloggo-rollup\index.ts'
rpt2: cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/code/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2: cache miss
rpt2: cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/syntacticDiagnostics/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2: cache miss
rpt2: cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/semanticDiagnostics/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2: cache miss
[!] Error: Cannot call a namespace ('qrcode')
index.ts (2:9)
1: import * as jsqr from 'jsqr';
2: import * as qrcode from 'qrcode-generator';
^
3:
4: const qr = qrcode(0, 'H');
error Command failed with exit code 1.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Angular 8 Moment - Error: Cannot call a namespace ('moment')
I had two individual .js files in my frontend directory with this import statement. Adapted both as you described and the maven build...
Read more >cannot find module 'fs' or its corresponding type declarations.
I needed to import file system('fs') and 'path' global node methods in my app.ts file but it keeps throwing: error TS2307: Cannot find...
Read more >@rollup/plugin-typescript - npm
A Rollup plugin for seamless integration between Rollup and Typescript. Requirements. This plugin requires an LTS Node version (v14.0.0+) and ...
Read more >Error: Cannot call a namespace ('algoliasearch') - Open Q&A
I think your issue is related to how rollup is handling import and typescript. There is known issue for all packages (not just...
Read more >isolatedModules - TSConfig Option - TypeScript
Some examples of code which does not work when isolatedModules is enabled. ... will not try to export it (this would be a...
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 FreeTop 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
Top GitHub Comments
See also this thread: https://github.com/rollup/rollup/issues/670
You might need
rollup-plugin-commonjs
plugin there - it rewrites commonjs modules from npm for rollup consumption.