Skip to content

Cannot use import statement outside a module #1

@danreeves

Description

@danreeves
node_modules/remix-hono/build/handler.js:1
import { createRequestHandler } from "@remix-run/server-runtime";
^^^^^^

SyntaxError: Cannot use import statement outside a module

I can resolve this by adding "type": "module" to your package.json, but would you recommend some other solution like bundling the server?

I'm currently using node v18.9.0 in mjs mode like:

import { installGlobals, broadcastDevReady } from "@remix-run/node"
import { Hono } from "hono"
import { serve } from "@hono/node-server"
import * as rh from "remix-hono/handler"
import * as build from "./build/index.mjs"

installGlobals()

if (process.env.NODE_ENV === "development") broadcastDevReady(build)

const server = new Hono()

server.use(
	"*",
	rh.remix({
		build,
		mode: process.env.NODE_ENV,
		// getLoadContext is optional, the default function is the same as here
		getLoadContext(ctx) {
			return ctx.env
		},
	})
)

serve(server, (info) => {
	console.log(`Listening on http://localhost:${info.port}`) // Listening on http://localhost:3000
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions