Closed bogacg closed 5 years ago
import diff from 'fast-diff'; -> import diff = require('fast-diff');
I have the same error when I try to
yarn add react-quill
I'm using React and Typescript
it seems to be coming from Delta.d.ts
How can I resolve this?
file: node_modules\fast-diff\diff.d.ts (line number 20) export = diff
to export default diff
file: node_modules\quill-delta\dist\Delta.d.ts (line number 32) export = Delta;
to export default Delta
will solve the issue. Working well for me now.
The simplest way to fix this issue is to set the compilerOption "esModuleInterop": true
in your tsconfig.json.
The modules fast-diff and quill-delta are exported using export =
because this is the only way they can be backwards-compatible with CommonJS require statements like const diff = require('fast-diff')
.
Using Babel, you can then write import diff from 'fast-diff'
because of Babel's module interop behavior. TypeScript originally did not have this interop, forcing you to write import diff = require('fast-diff')
, but this is ugly, and they changed their mind in 2.7 to be like Babel. They put the new behavior behind a flag because it is breaking, but they "highly recommend" you use the new behavior.
We could change Delta.ts to say import diff =
, but the point of TypeScript's change to module interop is that no one should have to type that anymore, so let me know if turning on the new module interop isn't a valid solution for you.
@dgreensp What a nice answer, it solved the issue. Thanks :)
@dgreensp This is not working for me. I turned on this option, this is my tsconfig.ts
file:
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"importHelpers": true,
"esModuleInterop": true,
"target": "es5",
"baseUrl": "./src",
"paths": {
"@angular/*": ["../node_modules/@angular/*"],
"app/*": ["app/*"],
"shared/*": ["app/shared/*"],
"shared": ["app/shared"],
"spec-helpers/*": ["app/spec-helpers/*"],
"spec-helpers": ["app/spec-helpers"],
"admin_app/*": ["app/admin_app/*"],
"admin_app": ["app/admin_app"],
"style_guides_app/*": ["app/style_guides_app/*"],
"style_guides_app": ["app/style_guides_app"]
},
"typeRoots": ["node_modules/@types"],
"types": ["node", "jasmine", "googlemaps"],
"lib": ["es2018", "dom"]
}
}
I still get the error:
node_modules/@types/quill/node_modules/quill-delta/dist/Delta.d.ts:1:8 - error TS1192: Module '"/home/admin/Documents/projects/project-angular/node_modules/@types/quill/node_modules/fast-diff/diff"' has no default export.
My Typescript version is ~3.2.2
I'm having the same problem, and esModuleInterop didn't work. Had to remove @types/quill for now because it caused build to fail.
I'm on Angular 9
with:
"quill": "1.3.7",
"@types/quill": "1.3.10",
Works fine, but when I update @types/quill
to version 2.0.3
I get the above-mentioned-error 🤷♂️
I was able to make the error go away by editing the tsconfig.json
in two different ways:
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
Add either of the above lines inside the "compilerOptions": { ... }
to fix ✅
for anyone coming through this problem, i believe the actual solution is not to mess with the compiler options but just to be careful with dependencies versions. If you use Quill, the default version is a v1.x. but the default @type/quill version is a v2.x.
juste use a @type/quill v1.x and everything will be all right ;)
I have an Angular app which started to give
"fast-diff/diff has no default export"
error upon build after I've updated my dependencies.I post it here because Error message begins with:
Please check.
UPDATE I removed @types/quill from dependencies, now I don't get error and build does not fail.