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 Kruhlmann

I was unable to reproduce the error in a new repository, so I'm guessing the issue is with something unrelated in the repository, which caused the error.

If I find out what is causing this I will open a new issue. Thank you for your help.

useful!

Related questions

Javascript Interpolation in Styles via CSS Variables? hot 2
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Uncaught TypeError: y.fragment.l is not a function hot 1
Increase elements when using a combination of await block and transition hot 1
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Change body class via &lt;svelte:body /&gt; hot 1
Site: Svelte Cookbook/ Examples hot 1
Missing dependencies in svelte/compiler type definitions hot 1
Multiple components in one file - svelte hot 1
onMount Error: Function called outside component initialization hot 1
A way to see if slot prop is present hot 1
slot inside #if inside #each : TypeError cannot read property 'd' of null hot 1
unclear / difficult to import uuidv4 hot 1
Use <script type="application/ld+json"> in <svelte:head> hot 1
Outros undefined when transitioning to another page hot 1
Github User Rank List