2

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

4
  • 1
    Can you share what adapter you are using to generate the build? Commented Aug 19, 2021 at 8:09
  • Sorry, my mistake, I added the reference to the node-adapter, which is what I'm using Commented Aug 19, 2021 at 18:36
  • 1
    Try running "node build". Also mention what version of node you are using Commented Aug 31, 2021 at 20:48
  • I've updated the question qith the SvelteKit and node version I'm using, thanks Commented Sep 1, 2021 at 12:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

whould you mind elaborating a little bit about it?
For further reading: redfin.engineering/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.