-
Notifications
You must be signed in to change notification settings - Fork 0
When trying to import in components: Cannot use import statement outside a module
#2
Comments
You absolutely can import components when doing SSR. I'm working on app that relies on this. The error you're seeing can be caused by different things it seems. It could be caused by using an outdated version of Node for example. Some issues I've found that might be relevant: sveltejs/sapper#936 EDIT: Can you try changing the following:
to:
I think Sapper probably does SSR differently to how we're doing it here. |
That change didn't do anything differently than before. I'm using node iex(6)> System.find_executable("node")
"/usr/local/bin/node" And
I'm not sure how to triage this - I've compared my rollup.config.js with others out there and it seems fine. I do believe this to be an issue with my setup somehow, except all I've done is follow the steps in the readme and here: https://dev.to/joshnuss/setup-phoenix-with-svelte-rollup-36dk Here is my rollup.config.js anyway: import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import autoPreprocess from 'svelte-preprocess';
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
// it's production mode if MIX_ENV is "prod"
const production = process.env.MIX_ENV == 'prod';
export default {
input: 'js/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: '../priv/static/js/app.js',
},
plugins: [
svelte({
preprocess: autoPreprocess({
scss: {
includePaths: ['./theme', './node_modules'],
},
}),
dev: !production,
emitCss: true,
}),
// the resolve plugin resolves modules located in node_modules folder
resolve({
browser: true,
dedupe: (importee) =>
importee === 'svelte' || importee.startsWith('svelte/'),
}),
commonjs(),
postcss({
minimize: production,
sourceMap: true,
}),
production && terser(),
],
watch: {
clearScreen: false,
},
}; |
It's like the svelte code isn't being parsed prior to being rendered |
After updating my mix.exs to point to master on this repo instead of the released version, I had a copy of
the problem remains |
however i think that's because the |
Simple example:
This results in:

Controller code:
Is it not possible to import other components when doing SSR?
The same component code renders fine outside of SSR.
The text was updated successfully, but these errors were encountered: