Skip to content

Cannot run nixi build or nuxi prepare, if node_modules is not in the project root #1090

@ashleysommer

Description

@ashleysommer

I know this is a fairly unsual setup.
Due to the corporate restrictions on the company laptop I'm using, I cannot keep my node_modules folder in the root of my Nuxt project.

Instead, I use the yarn "modules-folder" option to designate a different place to keep the node_modules folder on the system.

For example:

  • My project "H:\Home\Me\Projects\nuxt_project\"
  • The node_modules directory "C:\node\nuxt_project\node_modules"

I set the NODE_PATH environment variable with the location of the relevant node_modules location when invoking node commands, and it is able to correctly resolve the project dependencies.

The problem comes when invoking nuxi with commands build, prepare, preview, add, analyze, and some others.

 ERROR  Cannot resolve module "@nuxt/kit" (from: H:\Home\Me\Projects\nuxt_project\)                                                                                                                                                                                                                  7:07:03 pm  

    at resolveModuleURL (/C:/node/nuxt_project/node_modules/exsolve/dist/index.mjs:1294:19)
    at resolveModulePath (/C:/node/nuxt_project/node_modules/exsolve/dist/index.mjs:1313:20)
    at loadKit (/C:/node/nuxt_project/node_modules/@nuxt/cli/dist/shared/cli.qKvs7FJ2.mjs:6:21)
    at Object.run (/C:/node/nuxt_project/node_modules/@nuxt/cli/dist/chunks/build.mjs:42:23)
    at runCommand (/C:/node/nuxt_project/node_modules/citty/dist/index.mjs:316:26)
    at async runCommand (/C:/node/nuxt_project/node_modules/citty/dist/index.mjs:307:11)
    at async runMain (/C:/node/nuxt_project/node_modules/citty/dist/index.mjs:445:7)

My understanding of this issue is that nuxi uses exsolve resolver in the loadKit() function, when it tries to find the location of @nuxt/kit. Exsolve does not take into account the NODE_PATH env var, and also loadKit() uses the { from: rootDir } argument.
So that means nuxi always looks for @nuxt/kit in the project root dir, and cannot find it.

Is there any known way around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions