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

Starting a built project trigger error: Cannot find module '.../.output/server/node_modules/.../index.js' imported from .../.output/server/index.mjs #177

Open
lominming opened this issue Feb 1, 2024 · 9 comments

Comments

@lominming
Copy link

Problem: I can build the project successfully (vinxi build) but cannot start the built project (vinxi start). This is blocking us from pushing to production now since we upgrade solid-start.

Context: Wasn't sure whether this is directly a Vinxi bug or a Solid-Start bug. There's a thread going on in Discord but was suggested to open an issue. @nksaraf


Description:

This is a new issue since upgrading to solid-start 0.4.0 (beta2)

Build works vinxi build but starting the built project vinxi start will fail with this error:

Cannot find module '.../.output/server/node_modules/drizzle-orm/postgres-js/index.js' imported from .../.output/server/index.mjs


The .output/server/index.mjs file looks like:

...
import 'drizzle-orm/postgres-js';
import 'drizzle-orm/postgres-js/migrator';
import 'drizzle-orm';
...

And inside .output/server/node_modules/drizzle-orm is missing the folder postgres-js


Node: 20.5.1

"@solidjs/start": "^0.4.10"
"solid-js": "^1.8.12"
"vinxi": "^0.1.4"
@nksaraf
Copy link
Owner

nksaraf commented Feb 2, 2024

Is there a reproduction? Ill try to add drizzle to a project and see if that shows the problem

@andreiborza
Copy link

andreiborza commented Jul 11, 2024

I'm running into an issue like this in a monorepo where we run several e2e test apps of all kinds of frameworks. For example a solidjs app and a solidstart app.

We aren't using drizzle, but one of our own packages that has an optional peer dependency on solid router.

As mentioned here, this issue happens out of the box with a project created via yarn create solid and was only fixable by downgrading to solidjs to 1.8.17.

We're using pnpm, but I've also had this issue with yarn. It does not happen outside of our repo.

@lominming
Copy link
Author

@nksaraf This problem resurfaced again. This problem basically exists when .output/server/index.mjs references a file but that file does not exist in node_modules folder.

Question: Is there a way to force the bundler to include some modules/packages? This could possibly be fixed with a config, but I could not find the relevant config.

I tried using externals, optimizeDeps, etc. does not seem to work.

@nksaraf
Copy link
Owner

nksaraf commented Jul 18, 2024

which dependency is this? we could find the appropriate place to configure this.

@lominming
Copy link
Author

@nksaraf I managed to create a minimal repo: https://stackblitz.com/edit/vitejs-vite-owbuqy?file=src%2Froutes%2Findex.tsx,src%2Fapp.tsx,package.json

There is only 1 index file essentially, which calls a use server function.
This function could seem quite complex because I am using build from vite on the backend, but this error has happened the last time with out packages too, so I suspect is some tree-shaking/bundling issues.

  1. npm run dev works perfectly fine
  2. npm run build works file
  3. npm start production build will error out because .output/server/node_modules are missing some files. For some reason, only part of some files are copied over.

I have tried many configurations related to external and optmizeDeps on Nitro, Vite, etc. but none of them seem to work.

@andreiborza
Copy link

Here's another example repropduction:

https://stackblitz.com/~/github.com/andreiborza/vinxi-solidstart-sentry?file=package.json

  1. yarn build
  2. yarn start -> failure
Sentry Logger [warn]: Failed to register ESM hook Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/andreiborza/vinxi-solidstart-sentry/.output/server/node_modules/import-in-the-middle/hook.mjs' imported from /home/andreiborza/vinxi-solidstart-sentry/.output/server/node_modules/@sentry/node/build/esm/sdk/initOtel.js
Did you mean to import import-in-the-middle/hook.mjs?
    at __node_internal_captureLargerStackTrace2 (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:101:5335)
    at new NodeError (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:101:4149)
    at finalizeResolution (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:158:10970)
    at moduleResolve (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:158:11119)
    at defaultResolve (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:158:12372)
    at nextResolve (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:151:8835)
    at Hooks.resolve (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:151:3272)
    at ModuleLoader.resolve (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:154:2888)
    at ModuleLoader.getModuleJob (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:154:1938)
    at ModuleLoader.import (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:154:2657)
    at Hooks.register (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:151:1810)
    at _0x29e21a.handleMessage (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:162:1705)
    at [nodejs.internal.kHybridDispatch] (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:102:8637)
    at t.emitMessage (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/builtins.6410eae8.js:169:364)
    at https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/blitz.60a75bde.js:40:883114
    at https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/blitz.60a75bde.js:40:194895
    at _0x92b6d1 (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/blitz.60a75bde.js:40:195009)
    at MessagePort._0x4b7f82 (https://vinxisolidstartsentry-2ovc.w-credentialless-staticblitz.com/blitz.60a75bde.js:40:882988) {
  url: 'file:///home/andreiborza/vinxi-solidstart-sentry/.output/server/node_modules/import-in-the-middle/hook.mjs',
  code: 'ERR_MODULE_NOT_FOUND'
}

When looking at .output/server/node_modules/import-in-the-middle and comparing it to node_modules/import-in-the-middle, a lot of files are missing.

Looking through all package.jsons I spot three versions of import-in-the-middle

^1.11.0 used in @sentry/node
^1.8.1 used in @opentelemetry/instrumentation and
^1.7.1 used in opentelemetry-instrumentation-fetch

I'm bringing this up because last time (#177 (comment)) this problem was solved by aligning versions of solidjs used.

I also suspect some tree-shaking/bundling issues as @lominming mentioned.

@andreiborza
Copy link

andreiborza commented Aug 12, 2024

@nksaraf This problem resurfaced again. This problem basically exists when .output/server/index.mjs references a file but that file does not exist in node_modules folder.

Question: Is there a way to force the bundler to include some modules/packages? This could possibly be fixed with a config, but I could not find the relevant config.

I tried using externals, optimizeDeps, etc. does not seem to work.

@lominming You could do something like this but seems very brittle, also does not copy dependencies drizzle-orm depends on so...

import copy from 'rollup-plugin-copy'
import {defineConfig} from "@solidjs/start/config";

export default defineConfig({
    server: {
        rollupConfig: {
            plugins: [
                copy({
                    targets: [{
                        src: 'node_modules/drizzle-orm',
                        dest: '.output/server/node_modules',
                    }],
                    hook: 'writeBundle',
                })
            ]
        }
    }
});

@Lukjuh
Copy link

Lukjuh commented Aug 26, 2024

Im using Tanstack start with Coolify and also get this error:

[2024-Aug-26 13:30:01.012656] > [email protected] start
> vinxi start


> [email protected] start
> vinxi start


> [email protected] start
> vinxi start


> [email protected] start
> vinxi start

[2024-Aug-26 13:30:01.015781] at defaultResolve (node:internal/modules/esm/resolve:1193:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
at ModuleLoader.import (node:internal/modules/esm/loader:336:34)
at importModuleDynamically (node:internal/modules/esm/translators:143:35)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:176:14)



ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs


ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs

at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:327:11)
at moduleResolve (node:internal/modules/esm/resolve:980:10)
at defaultResolve (node:internal/modules/esm/resolve:1193:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
at ModuleLoader.import (node:internal/modules/esm/loader:336:34)
at importModuleDynamically (node:internal/modules/esm/translators:143:35)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:176:14)



ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs


ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs

at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:327:11)
at moduleResolve (node:internal/modules/esm/resolve:980:10)
at defaultResolve (node:internal/modules/esm/resolve:1193:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
at ModuleLoader.import (node:internal/modules/esm/loader:336:34)
at importModuleDynamically (node:internal/modules/esm/translators:143:35)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:176:14)



ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs


ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs

at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:327:11)
at moduleResolve (node:internal/modules/esm/resolve:980:10)
at defaultResolve (node:internal/modules/esm/resolve:1193:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
at ModuleLoader.import (node:internal/modules/esm/loader:336:34)
at importModuleDynamically (node:internal/modules/esm/translators:143:35)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:176:14)



ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs


ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs

at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:327:11)
at moduleResolve (node:internal/modules/esm/resolve:980:10)
at defaultResolve (node:internal/modules/esm/resolve:1193:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
at ModuleLoader.import (node:internal/modules/esm/loader:336:34)
at importModuleDynamically (node:internal/modules/esm/translators:143:35)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:176:14)



ERROR Cannot find module '/app/.output/server/index.mjs' imported from /app/node_modules/vinxi/bin/cli.mjs

@andreiborza
Copy link

I think this is related to vercel/nft#428 and might be solved with unjs/nitro#2703 (hopefully) landing in nitropack.

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