Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bogacg opened this issue Oct 15, 2018 · 10 comments · Fixed by whyboris/JSON-i18n-Editor#8
Closed

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

bogacg opened this issue Oct 15, 2018 · 10 comments · Fixed by whyboris/JSON-i18n-Editor#8

Comments

@bogacg
Copy link

bogacg commented Oct 15, 2018

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
Copy link

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

@wvyeun
Copy link

wvyeun commented Nov 5, 2018

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
Copy link

sumitvekariya commented Nov 5, 2018

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
Copy link
Contributor

dgreensp commented Nov 5, 2018

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 dgreensp closed this as completed Nov 5, 2018
@dave0688
Copy link

dave0688 commented Nov 8, 2018

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

@Olgagr
Copy link

Olgagr commented Aug 20, 2019

@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
Copy link

Hukutus commented Aug 30, 2019

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
Copy link

whyboris commented May 3, 2020

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
Copy link

whyboris commented Jan 21, 2021

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 ✅

@fdeguibert
Copy link

fdeguibert commented Jul 17, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants