Import error in my Angular project
See original GitHub issueI have the import script from the sample
...
import createReport from 'docx-templates';
import fs from 'fs';
...
but getting error in browser
Failed to compile.
node_modules/docx-templates/lib/main.d.ts:3:8 - error TS1259: Module '"/home/weilies_chok/apps/my-app/node_modules/jszip/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
3 import JSZip from 'jszip';
~~~~~
node_modules/jszip/index.d.ts:270:1
270 export = JSZip;
~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
compiler error
✔ Browser application bundle generation complete.
5 unchanged chunks
Build at: 2021-04-29T03:04:50.495Z - Hash: 54914e41f6300bfbc2a7 - Time: 476ms
Error: node_modules/docx-templates/lib/main.d.ts:3:8 - error TS1259: Module '"/home/weilies_chok/apps/my-app/node_modules/jszip/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
3 import JSZip from 'jszip';
~~~~~
node_modules/jszip/index.d.ts:270:1
270 export = JSZip;
~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
Error: src/app/app.component.ts:3:8 - error TS1192: Module '"fs"' has no default export.
3 import fs from 'fs';
~~
package.json
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~11.2.4",
"@angular/common": "~11.2.4",
"@angular/compiler": "~11.2.4",
"@angular/core": "~11.2.4",
"@angular/elements": "^11.2.4",
"@angular/forms": "~11.2.4",
"@angular/platform-browser": "~11.2.4",
"@angular/platform-browser-dynamic": "~11.2.4",
"@angular/router": "~11.2.4",
"angular-formio": "^4.11.4",
"bootstrap": "^4.6.0",
"docx-templates": "^4.6.0",
"fs": "*",
"nativescript-ibeacon": "^0.8.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1102.3",
"@angular/cli": "~11.2.3",
"@angular/compiler-cli": "~11.2.4",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.1.5"
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Angular import module error
1. you have to import the Material module · All the material design modules are imported on app. · import the SharedModule in...
Read more >Errors List
Errors Listlink · NG0100: Expression Changed After Checked · NG01003: Wrong Async Validator Return Type · NG01203: Missing value accessor · NG0200: Circular ......
Read more >Introduction to modules
They can import functionality that is exported from other NgModules, and export selected functionality for use by other NgModules. Every Angular application has ......
Read more >Frequently-used modules
When you use these Angular modules, import them in AppModule , or your feature module as appropriate, and list them in the @NgModule...
Read more >NgModule FAQ
To avoid this problem, import the HttpClientModule only in the AppModule , the application root module. If you must guard against this kind...
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
Just some ideas:
fs
this is not useable in browsers (so unless your writing a Angular page for electron don’t use fs)Instead of fs you have to use the
fetch
api to get the .docx file from your server or use<input type="file">
to get the file or the new Native Filesystem API (see https://caniuse.com/?search=native file )I assume this is fixed since #216? Feel free to reopen if not.