slab / delta

Simple and expressive JSON format for describing rich-text content and their changes
https://quilljs.com/docs/delta
BSD 3-Clause "New" or "Revised" License
914 stars 130 forks source link

"fast-diff/diff has no default export" error #33

Closed bogacg closed 5 years ago

bogacg commented 6 years ago

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:

ERROR in node_modules/@types/quill/node_modules/quill-delta/dist/Delta.d.ts(1,8):

Please check.

UPDATE I removed @types/quill from dependencies, now I don't get error and build does not fail.

boscohyun commented 6 years ago

import diff from 'fast-diff'; -> import diff = require('fast-diff');

wvyeun commented 5 years ago

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?

sumitvekariya commented 5 years ago

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.

dgreensp commented 5 years ago

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.

dave0688 commented 5 years ago

@dgreensp What a nice answer, it solved the issue. Thanks :)

Olgagr commented 5 years ago

@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

Hukutus commented 5 years ago

I'm having the same problem, and esModuleInterop didn't work. Had to remove @types/quill for now because it caused build to fail.

whyboris commented 4 years ago

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 🤷‍♂️

whyboris commented 3 years ago

I was able to make the error go away by editing the tsconfig.json in two different ways:

Add either of the above lines inside the "compilerOptions": { ... } to fix ✅

fdeguibert commented 3 years ago

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 ;)