profile
viewpoint

Ask questionsError: 'default' is not exported when using babel + moment

Svelte version 3.4.2 Rollup version 1.12.3

I am trying to integrate babel with my existing svelte + rollup configuration.

I ran into issues, specifically with the moment library, when bundling together with babel.

The problem occurs when I import moment with import moment from "moment", and get the following error: Error: 'default' is not exported by node_modules\moment\moment.js

This only occurs when babel is included in the rollup configuration, and moment works as expected without it.

Most of the cases of this error occurring seem to be related to not having "allowSyntheticDefaultImports": true in the typescript config file, but since I'm not using typescript I don't know how I can resolve this.

I've included my rollup configuration below.

<details> <summary>rollup.config.js</summary>

import svelte from "rollup-plugin-svelte";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import babel from 'rollup-plugin-babel';  
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import { scss } from "@kazzkiq/svelte-preprocess-scss";

const production = !process.env.ROLLUP_WATCH;

export default {
	input: "src/main.js",
	output: {
		sourcemap: true,
		format: "iife",
		name: "app",
		file: "dist/bundle.js"
	},
	plugins: [
		svelte({
			preprocess: {
				style: scss(),
			},
			dev: !production,
			css: css => {
				css.write("dist/bundle.css");
			}
		}),
		babel({
                        extensions: [ ".js", ".mjs", ".html", ".svelte" ]
                }),
		resolve(),
		commonjs(),
		!production && livereload("dist"),
		production && terser(),
	],
	watch: {
		clearScreen: false
	}
};

</details>

sveltejs/svelte

Answer questions ajaysinghj8

@Kruhlmann

import moment from 'moment';   

works fine. It just that you need to configure the editor to turn off "Svelte> Plugin > Typescript".

File > Perference > settings Screen Shot 2019-06-10 at 3 37 57 AM

useful!
source:https://uonfu.com/
Github User Rank List