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

Vite Production build putting files in ./build/build/assets (One build folder too deep) #8038

Closed
nicksrandall opened this issue Nov 17, 2023 · 8 comments

Comments

@nicksrandall
Copy link
Contributor

Reproduction

https://stackblitz.com/edit/remix-run-remix-jsc5mp?file=public%2Fvite.config.ts

System Info

System:
    OS: macOS 14.2
    CPU: (12) arm64 Apple M3 Pro
    Memory: 388.63 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/Library/pnpm/node
    Yarn: 1.22.19 - ~/Library/pnpm/yarn
    npm: 10.1.0 - ~/Library/pnpm/npm
    pnpm: 8.10.5 - ~/Library/pnpm/pnpm
    bun: 1.0.11 - ~/.bun/bin/bun
    Watchman: 2023.11.06.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.2
  npmPackages:
    @remix-run/dev: 2.3.0 => 2.3.0
    @remix-run/eslint-config: 2.3.0 => 2.3.0
    @remix-run/express: 2.3.0 => 2.3.0
    @remix-run/node: 2.3.0 => 2.3.0
    @remix-run/react: 2.3.0 => 2.3.0
    @remix-run/serve: 2.3.0 => 2.3.0
    @remix-run/server-runtime: 2.3.0 => 2.3.0
    vite: 4.5.0 => 4.5.0

Used Package Manager

npm

Expected Behavior

I expect Vite plugin to match output of Remix (esbuild) compiler.

Actual Behavior

Server assets are in one folder too deep.

@paul-phan
Copy link

Confirm to get the same problem after migrating Remix from 2.2.0 to v2.3.0

@nicksrandall
Copy link
Contributor Author

FWIW, this issue is not fixed by the work around described here: #8023 (comment)

I thought the two issues were related but maybe not?

@markdalgleish
Copy link
Member

markdalgleish commented Nov 17, 2023

If I'm understanding correctly, this might be the same issue. The server build directory is not meant to have an assets directory, let alone a build/assets directory nested within it. I think this was being caused by Vite's behaviour of copying the public directory into outDir, which the comment you link to describes how to disable.

Is the issue you've raised actually causing any issues with actual runtime behaviour? If you delete the build/build directory, does your app still work correctly when running npm start?

@paul-phan
Copy link

I believe I have encountered another issue. Perhaps you could try using indie or blue stack. Previously, running vite build -ssr would generate a build/index.js file, and the server code would be placed in build/assets. However, it appears that the build/assets folder is now removed immediately after the build process is completed.
Screenshot 2023-11-17 at 12 31 26

@nicksrandall
Copy link
Contributor Author

nicksrandall commented Nov 17, 2023

Yes. The app does not work at runtime because it's looking for a js file in the assets directory that is not there. It might work if I configure my server to pull from ./build/build. I'll test that.

UPDATE: Nope, still doesn't work

@dmarkow
Copy link
Contributor

dmarkow commented Nov 17, 2023

Seeing the same issue. 2.3.0-pre.0 works fine, 2.3.0-pre.1 and 2.3.0 do not:

± yarn start
yarn run v1.22.19
$ remix-serve ./build/index.js
Error: Cannot find module '/Users/dylan/dev/pfcs/build/assets/remix-form-WrDF9P50.js' imported from /Users/dylan/dev/pfcs/build/index.js
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:233:11)
    at moduleResolve (node:internal/modules/esm/resolve:845:10)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

npx create-remix@latest --template remix-run/remix/templates/unstable-vite has the same nested build folder, but it seems to start up fine, maybe because nothing in the assets folder is actually being required in the template app.

@markdalgleish
Copy link
Member

@nicksrandall Am I understanding correctly that your original issue is fixed by #8039, but you're now hitting this issue: #8041 — which should be fixed by #8042?

@markdalgleish
Copy link
Member

The original issue raised should be fixed in the short term by #8039, but we're also shipping a better fix by changing the structure of our build output to avoid writing files into public: #8077.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants