#Remix Dev Won't Run (V2)

1 messages · Page 1 of 1 (latest)

feral pasture
#

Hi I have an issue running my dev server with my express server. Here are some information,

package.json

    "build": "run-s build:*",
    "build:remix": "remix build \"node ./other/build-info.js\"",
    "build:server": "esbuild --platform=node --format=cjs ./server/index.ts --outfile=build/server.js",
    "dev": "run-p dev:*",
    "dev:build": "cross-env NODE_ENV=development npm run build:server -- --watch",
    "dev:content": "node -r esbuild-register -r dotenv/config other/refresh-on-content-change.ts",
    "dev:app": "remix dev -c \"node --inspect --require dotenv/config --require ./tests/mocks ./build/server.js\"",

server/index.ts
(image attached)

After I run npm run dev I only got this (image attached)

It happened after I migrated to V2. Does anyone know what I am missing?

nova moon
#

not sure if this is related, but the purgeRequireCache stuff in your server file looks outdated. if you aren't using --manual flag of remix dev, purging the require cache is unnecessary. and even if you are using --manual, the way you have it set up is suboptimal.

^that's probably not what's causing your issue, but makes me think that you might have outdated setup

#

The screenshot you showed doesn't show any errors. I'm guessing you are missing the console.log with your app server IP? is that the issue?

feral pasture
#

Thanks for the correction

#

Anw, I still cannot open my web in localhost.

#

If you see in server/index.ts:93 I already put console log there,

#
app.listen(port, () => {
  console.log(`✅ app ready: http://localhost:${port}`);

  if (process.env.NODE_ENV === "development") {
    broadcastDevReady(build);
  }
});
#

Anw, do you have more suggestion about my server setup? @nova moon

mighty osprey
feral pasture
#

Mine is quite different. I'll try to change my server/index.ts to follow from remix express template.

#

I'll inform the result here.

feral pasture
#

I change my server/index.ts into this,

#

But the result still the same

#
> [email protected] dev
> run-p dev:*

> [email protected] dev:app
> remix dev -c "node --inspect --require dotenv/config --require ./tests/mocks ./build/server.js"

> [email protected] dev:content
> node -r esbuild-register -r dotenv/config other/refresh-on-content-change.ts

> [email protected] dev:build
> cross-env NODE_ENV=development npm run build:server -- --watch


> [email protected] build:server
> esbuild --platform=node --format=cjs ./server/index.ts --outfile=build/server.js --watch

[watch] build finished, watching for changes...
▲ [WARNING] "tsconfig.json" does not affect esbuild's own target setting [tsconfig.json]

    tsconfig.json:11:4:
      11 │     "target": "ES2022",
         ╵     ~~~~~~~~

  This is because esbuild supports reading from multiple
  "tsconfig.json" files within a single build, and using
  different language targets for different files in the same
  build wouldn't be correct. If you want to set esbuild's
  language target, you should use esbuild's own global "target"
  setting such as with "--target=es2022".

✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

    server/index.ts:19:21:
      19 │ const initialBuild = await reimportServer();
         ╵                      ~~~~~

✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

    server/index.ts:22:6:
      22 │     ? await createDevRequestHandler(initialBuild)
         ╵       ~~~~~

1 warning and 2 errors

 💿  remix dev

 info  building...
 info  built (1.5s)
Debugger listening on ws://127.0.0.1:9229/bce96028-f485-412b-8149-5a988e3990ef
For help, see: https://nodejs.org/en/docs/inspector
🔶 Mock server installed
#

I still cannot open it on local

#

If I change my dev script into this "dev:app": "remix dev -c \"node --watch ./build/server.js\"", the result is,

1 warning and 2 errors

 💿  remix dev

 info  building...
 info  built (1.3s)
(node:36935) ExperimentalWarning: Watch mode is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/hanihusam/Dev/hanihusam.com/build/index.js:15
import invariant from "tiny-invariant";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/Users/hanihusam/Dev/hanihusam.com/build/server.js:73:15)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
Failed running './build/server.js'
#

Ah finally, it works now

#

It's resolved by I add serverModuleFormat: "cjs", on my remix config

feral pasture
#

Anw, how can I fix this errors and warning,

▲ [WARNING] "tsconfig.json" does not affect esbuild's own target setting [tsconfig.json]

    tsconfig.json:11:4:
      11 │     "target": "ES2022",
         ╵     ~~~~~~~~

  This is because esbuild supports reading from multiple
  "tsconfig.json" files within a single build, and using
  different language targets for different files in the same
  build wouldn't be correct. If you want to set esbuild's
  language target, you should use esbuild's own global "target"
  setting such as with "--target=es2022".

✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

    server/index.ts:19:21:
      19 │ const initialBuild = await reimportServer();
         ╵                      ~~~~~

✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

    server/index.ts:22:6:
      22 │     ? await createDevRequestHandler(initialBuild)
         ╵       ~~~~~

1 warning and 2 errors
latent echo