Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to deploy SolidStart with node though it works locally #758

Closed
MattStopa opened this issue Feb 20, 2023 · 8 comments
Closed

Unable to deploy SolidStart with node though it works locally #758

MattStopa opened this issue Feb 20, 2023 · 8 comments

Comments

@MattStopa
Copy link

MattStopa commented Feb 20, 2023

So I have a bare bones JS only SolidStart app I created today, brand new. Node version is 18.

I create the initial app with the counter. It works great right out of the box. I do a build. I go into the dist directory and run node server.js. Works exactly the same.

I have a DO box I created just for this purpose. I scp the files over, no changes. Go into the directory and get the following error:

nyc1-01:/home/app/dist# node server.js
(node:3794) 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/app/dist/server.js:1
import require$$1, { resolve, join, normalize, dirname } from 'path';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.12.1

I've looked through existing bugs but most of them focus on Prisma being an issue so I specifically avoided adding it. I read some documentation on the SolidStart site that you may need an adapter but didn't see anything about what I needed to use. Also, for whatever reason the node app has no trouble running.

I'm thoroughly confused why this would happen on remote boxes but not my own. I'm not sure if this is a bug or designed behavior (seems unlikely).

If this is an uncaught bug that's fine or if I'm just pointed in the wrong direction please let me know.

Thank you

    "solid-js": "^1.6.10",
    "solid-start": "^0.2.17",

Mind boggling to me why this works locally but not on any server...

@rolanday
Copy link

rolanday commented Feb 21, 2023

Hi Matt, fyi, I'm on 0.2.21 and deploying to EC2 instance w/o any issues (using node adapter). [edit: I'm on node 16.16.0/AWS Linux2]

Regarding prisma, I used workaround documented here: // #398 (comment)

i.e., ...

import {
	PrismaClient as ImportedPrismaClient
} from "@prisma/client";
import { createRequire } from "module";
const require = createRequire(import.meta.url ?? __filename);
const { PrismaClient: RequiredPrismaClient } = require("@prisma/client");
const _PrismaClient: typeof ImportedPrismaClient = RequiredPrismaClient;
export class PrismaClient extends _PrismaClient {}

Odd that no such issue and hack needed for SvelteKit, which also packages using Vite / requires esm.

@MattStopa
Copy link
Author

Weird... What is the Node adapter exactly? Is that something I need to add in specifically?

@rolanday
Copy link

Unlike SvelteKit, node adapter is configured by default (at least my starter template was, which was auth-core option when creating new project). Screenshot below (note adapter:node). I haven't had any reason to explore further since I'm deploying to EC2 (so need node).

Screen Shot 2023-02-22 at 2 55 27 AM

@arbassett
Copy link
Contributor

arbassett commented Feb 24, 2023

@MattStopa can you confirm you have "type": "module" in your package.json and its on your server

also can you clarify how you are getting your files on your server.. are you just copying the dist directory or the whole app and building it?

@boehs
Copy link
Contributor

boehs commented Feb 24, 2023

also, is your node on DO >=v16.2?

@MattStopa
Copy link
Author

@MattStopa can you confirm you have "type": "module" in your package.json and its on your server

also can you clarify how you are getting your files on your server.. are you just copying the dist directory or the whole app and building it?

Yes type = module. I just copied the dist over. Am I supposed to do the build on that machine? I didn't even consider doing that.

@arbassett
Copy link
Contributor

arbassett commented Feb 25, 2023

@MattStopa can you confirm you have "type": "module" in your package.json and its on your server
also can you clarify how you are getting your files on your server.. are you just copying the dist directory or the whole app and building it?

Yes type = module. I just copied the dist over. Am I supposed to do the build on that machine? I didn't even consider doing that.

If you don't have any native dependencies just copying the dist folder is fine but you will also need to copy the package.json.. what you can try first is change the extension from .js to .mjs

@MattStopa
Copy link
Author

So... I just went ahead and built on my target machine and it works fine. That didn't work well because I was using a shared webhost and couldn't do an NPM install there but I tired on DO and it works fine. So there's that at least. I'm going to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants