export declarations may only appear at top level of a module
See original GitHub issueI’m facing an issue that seems very similar to #328 however it is occurring at runtime. I’m trying to add Routify to an existing application and getting the following error:
Firefox
Uncaught SyntaxError: export declarations may only appear at top level of a module
Brave
Uncaught SyntaxError: Unexpected token 'export'
I’ve gone through the documentation and changed my rollup.config.js output.format to esm as well as using output.dir instead of output.file.
I also found this similar issue in Sapper repo but it was closed without any comment/resolution.
app.ts
import App from './App.svelte';
const app = new App({
target: document.body
});
export default app;
App.svelte
<script>
import { Router } from '@roxy/routify';
import { routes } from '../.routify/routes';
</script>
<Router {routes} />
rollup.config.js
import svelte from 'rollup-plugin-svelte';
import sveltePreprocess from 'svelte-preprocess';
import css from 'rollup-plugin-css-only';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
const production = !process.env.ROLLUP_WATCH;
var serve = function() {
let server;
var toExit = function() {
if (server) {
server.kill(0);
}
}
return {
writeBundle() {
if (server) {
return;
}
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
}
}
export default {
input: 'src/app.ts',
output: {
name: 'app',
sourcemap: true,
format: 'esm',
dir: 'public/build'
},
plugins: [
svelte({
preprocess: sveltePreprocess({
sourceMap: !production
}),
compilerOptions: {
dev: !production
}
}),
css({
output: 'app.css'
}),
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
typescript({
sourceMap: !production,
inlineSources: !production
}),
!production && serve(),
!production && livereload('public')
]
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
SyntaxError: import declarations may only appear at top level ...
If I look in my browser debugger I see an error: "SyntaxError: import declarations may only appear at top level of a module"....
Read more >"export declarations may only appear at top level of a module ...
Describe the bug I am able to extract and compile without any problems, however using the @lingui/loader to load catalogs isn't working.
Read more >import declarations may only appear at top level of a module
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0. Steps to reproduce: First get "jsshell" from here:.
Read more >export declarations may only appear at top level of a module
The above line rectifies the syntaxError: Import declarations may only appear at top level of module. It's because when you import, the file...
Read more >import declarations may only appear at top level of a module ...
JavaScript : SyntaxError: import declarations may only appear at top level of a module [ Gift : Animated Search Engine ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve discovered the issue is related to how the script is being loaded and I’ve opened the following PR on the docs to hopefully help anyone else in the future.
https://github.com/roxiness/routify.dev/pull/224
https://jestjs.io/docs/ecmascript-modules