how to distribute build folder using SvelteKit

Viewed 1426

I've just compiled a SvelteKit application with the node-adepter issuing npm run build

this is the output I get

$ ls build/
assets  index.js pre-rendered

But When I try to execute it I get:

$ node build/index.js 
(node:103550) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/ubuntu/tmp/build/index.js:62
import http from "http";
^^^^^^

Which I could solve it creating a package.json file like this:

{
        "type": "module"
}

But then I get import errors unless I copy the whole node_modules folder to the build folder

Is this the right way to distribute the app?

I just want to copy the necessary files and start it with node build/indes.js

BTW I'm using SvelteKit 1.0.0-next.132 and node 16.6.1

1 Answers

Use

import * as http from 'http'; instead of import http from 'http';

You are probably trying to import a Non-ESM module using the ESM syntax which will not work.

Related