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

Module has no has no default export with ts and rollup #277

Closed
waitingsong opened this issue Jul 10, 2018 · 14 comments
Closed

Module has no has no default export with ts and rollup #277

waitingsong opened this issue Jul 10, 2018 · 14 comments

Comments

@waitingsong
Copy link
Contributor

import dayjs from 'dayjs'

compile with rollup , got error `Module

".../source/node_modules/dayjs/index" has no default export.

waitingsong added a commit to waitingsong/dayjs that referenced this issue Jul 10, 2018
@kaseyhinton
Copy link

any updates on this?

@Kikisek
Copy link

Kikisek commented Sep 13, 2018

Try import * as dayjs from 'dayjs', it helped me 😃

prantlf pushed a commit to prantlf/dayjs that referenced this issue Sep 15, 2018
## [1.10.1](v1.10.0...v1.10.1) (2018-09-15)

### Bug Fixes

* **typings:** default export issue[iamkun#277](https://github.com/prantlf/dayjs/issues/277) ([149d477](149d477))
* Do not clone the Date instance needlessly in toISOString ([088cdc5](088cdc5))
@aibrahim3546
Copy link

@Kikisek I did like what you mentioned...

like this:

import * as dayjs from dayjs

I am hitting this error now:

Uncaught TypeError: dayjs is not a function

@samtsai
Copy link

samtsai commented Dec 4, 2018

@aibrahim3546 to be sure, do you have quotes around the second dayjs?

import * as dayjs from 'dayjs'

@wangyiz4262
Copy link
Contributor

@waitingsong @iamkun I re-did the Typescript definition in #466 which should fix the problem of default import. The current index.d.ts file does not make much sense to expose class to the user.

iamkun pushed a commit that referenced this issue Feb 2, 2019
@iamkun
Copy link
Owner

iamkun commented Feb 2, 2019

Updates:

From v1.8.1 we could simply use import dayjs from 'dayjs' in a TypeScript project.

@iamkun iamkun closed this as completed Feb 2, 2019
@Smirking
Copy link

Smirking commented May 1, 2019

Looks like this was reverted again here #476, so it's broken again as of 1.8.4 for rollup and things that use rollup, ng-packagr etc

@conrado-l
Copy link

As @Smirking said, this is broken as of now and we have to use @Kikisek workaround.

@orige
Copy link

orige commented Jun 15, 2020

Even with @Kikisek workaround, I'm getting:
TypeError: dayjs is not a function

version: 1.8.28

@blestab
Copy link

blestab commented Oct 31, 2020

Also getting this version: 1.8.35

@existe-deja
Copy link

For those who are experiencing the Error: 'default' is not exported by node_modules/dayjs/dayjs.min.js issue, add @rollup/plugin-commonjs as a dev dependency and configure your jest.config.js like below:

import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from "rollup-plugin-terser";

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.min.js',
    format: 'cjs',
    plugins: [
      terser()
    ]
  },
  plugins: [
    nodeResolve(),
    commonjs()
  ]
};

@risalfajar
Copy link

1.10.7, error still happened

Have tried the workaround but still not working

dayjs is not a function

@sineraves
Copy link

Came across the Error: 'default' is not exported by node_modules/dayjs/dayjs.min.js error today with 1.10.7.

Had success with:

import dayjs from 'dayjs/esm';

@SeryiBaran
Copy link

It even worked for me with import dayjs from 'dayjs', with this config:

// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';

export default {
  input: './src/main.ts',
  output: {
    file: './build/main.js',
    format: 'cjs',
  },
  plugins: [
    resolve({
      exportConditions: ['node'],
    }),
    commonjs(),
    typescript(),
  ],
};

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