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

Plugin import in angular project throws error 'no default export' #613

Closed
BingeCode opened this issue Jun 11, 2019 · 6 comments
Closed

Plugin import in angular project throws error 'no default export' #613

BingeCode opened this issue Jun 11, 2019 · 6 comments

Comments

@BingeCode
Copy link

BingeCode commented Jun 11, 2019

Describe the bug
Plugin import throws error in angular project / browser
dayjs__WEBPACK_IMPORTED_MODULE_5__(...).month(...).startOf(...).weekday is not a function

Expected behavior
I can use most dayjs functions just fine with import * as dayjs from 'dayjs'.

But when I need to use plugins, I import with import * as weekday from 'dayjs/plugin/weekday, it throws me this error in the browser - even though the compiler recognises the function weekday just fine:

dayjs__WEBPACK_IMPORTED_MODULE_5__(...).month(...).startOf(...).weekday is not a function

image

Trying to import the weekday plugin with import weekday from 'dayjs/plugin/weekday'; throws compiler error Module '"C:/.../node_modules/dayjs/plugin/weekday"' has no default export.

OR import { weekday } from 'dayjs/plugin/weekday'; throws compiler error Module '"C:/.../node_modules/dayjs/plugin/weekday"' has no exported member

Information

  • Day.js Version 1.8.14
  • OS: Win 10 / Angular Typescript Project
  • Browser Chrome 74
@iamkun
Copy link
Owner

iamkun commented Jun 11, 2019

Please provide a test repo.

@thomascsd
Copy link

Use dayjs.extend, see doc

import * as dayjs from 'dayjs';
import * as weekday from 'dayjs/plugin/weekday';
dayjs.extend(weekday);

@JustFly1984
Copy link

JustFly1984 commented Aug 6, 2019

Ok, here is the thing, we have same or equal issues with gatsby.js, which is related to:
https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-typescript/README.md

Which is described as:
This plugin uses babel-plugin-transform-typescript to transpile TypeScript. It does not do type checking. Also since the TypeScript compiler is not involved, the following applies:

Does not support namespaces. Workaround: Move to using file exports, or migrate to using the module { } syntax instead.

Does not support const enums because those require type information to compile. Workaround: Remove the const, which makes it available at runtime.

Does not support export = and import =, because those cannot be compiled to ES.next. Workaround: Convert to using export default and export const, and import x, {y} from "z".

https://babeljs.io/docs/en/babel-plugin-transform-typescript.html

@JustFly1984
Copy link

the only workaround which works, is to setup tsconfig with

    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,

@iamkun
Copy link
Owner

iamkun commented Feb 12, 2020

@iamkun
Copy link
Owner

iamkun commented Jan 3, 2021

I'll close this issue since it's been a while since it's been opened. Feel free to reopen if you have updates on this

@iamkun iamkun closed this as completed Jan 3, 2021
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

No branches or pull requests

4 participants