The issue
The Nuxt 3 build exports module "cookie-es" as a reference, symbolic link or how it's called in Win. The reference will be empty after copying.
I propose a question
How do I tell Nuxt to export a module as a standard directory (if possible), or in the worse case, how do I copy a file in Windows droping references and making real files of them instead?
The problem showcase
how "node_modules" looks like after build (path....output\server\node_modules)
node_module cookie-es outside
how "node_modules" looks like after build (path....output\server\node_modules)
node_module cookie-es inside
how "node_modules" looks like after copied (otherPath....output\server\node_modules)
node_module cookie-es outside
how "node_modules" looks like after copied (otherPath....output\server\node_modules)
node_module cookie-es inside
where is it referencing files from? From "node_modules/.nitro"
node_module .nitro inside
In plain words only, content of a directory is lost after copying, due to a loss of a reference I quess.
Variables
OS: Windows 10
Nuxt: ^3.4.3
What I tried
I have tried disabling symlinks in vite config (inside nuxt.config)
vite: {
resolve: {
preserveSymlinks: false
}
}
AND
I have tried to manualy copy the files from the "build modules" into the lost gaps in "copied modules". It works but its not a possibility to manually find the problem ones and copy them every time.
Solution
I have solved the issue by auto-copying file (inside package.json)
"scripts": {
"build": "nuxt build",
"postbuild": "robocopy /e /j \".output/server/node_modules\"
\".output/server/node_modules_copy\" & rd /s /q
\".output/server/node_modules\" & robocopy /e /j
\".output/server/node_modules_copy\" \".output/server/node_modules\"
& rd /s /q \".output/server/node_modules_copy\""
}
It copies modules without symbolic links into a new directory and then copies it back as node_modules.
Please feel free to post a better solution, thanks
In general there are many packages that will fail to work as they are hopelessly dependent traditional
node_modulesdirectory structure, so anything that goes beyond the basic traditional spec of NPM will break some packages because the authors didn't take a modern adaptive approach when building their lib.PNPM
If you used
pnpmto instigate your project then issues around symbolic linking can arise, there are unfortunately many packages that wont work withpnpm.You might try the folloing configutation options:
https://pnpm.io/blog/2020/10/17/node-modules-configuration-options-with-pnpm#plugnplay-the-strictest-configuration
YARN 3
If you used
yarnyou can have a similar issue with certain packages not working because specifically because of the lack of anode_modulesdirectory in a project root, in the case of yarn you can fix package import issues using the node linker config in a.yarnrc.ymlfile in your project root.