ElMassimo / vite_ruby

⚑️ Vite.js in Ruby, bringing joy to your JavaScript experience
https://vite-ruby.netlify.app
MIT License
1.35k stars 123 forks source link

Asset bundling can fail silently in tests #132

Closed msakrejda closed 3 years ago

msakrejda commented 3 years ago

Description πŸ“–

When running Rails feature specs that require asset precompilation, if asset compilation fails (which can happen but doesn't appear to produce any output in the test), vite_ruby will cause template errors in looking up the assets, but the guidance is misleading:

$ bundle exec rspec spec/features/some_spec.rb 

Randomized with seed 31883
Capybara starting Puma...
* Version 5.3.2 , codename: Sweetnighter
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:44747
2021-10-11 12:11:33 -0700 Rack app ("GET /users/sign_in" - (127.0.0.1)): #<ActionView::Template::Error: Vite Ruby can't find entrypoints/application.ts in public/vite-test/manifest.json or public/vite-test/manifest-assets.json.

Possible causes:
  - The file path is incorrect.
  - The file is not in the entrypoints directory.
  - Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.

Visit the Troubleshooting guide for more information:
  https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting

In this case, everything was set up correctly, but we were simply running out of configured memory for node, so the asset build did not complete, and no manifest file was generated. See "Logs" section for details. Ideally, I think vite_ruby could inform the user that the asset build failed and show the underlying cause or give some troubleshooting information.

Reproduction 🐞

I'm not able to generate a minimal reproduction right now or share the project I'm working on. I hope the information above is still useful.

Vite Ruby Info _Run `bin/rake vite:info` and provide the output:_ ``` bin/vite present?: false vite_ruby: 3.0.0 vite_rails: 3.0.0 rails: node: v14.16.0 npm: 7.12.1 yarn: 1.22.5 pnpm: ruby: ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux] installed packages: pganalyze@1.0.0 /home/maciek/duboce-labs/pganalyze β”œβ”€β”¬ vite-jest@0.0.3 β”‚ └── vite@2.5.10 deduped β”œβ”€β”¬ vite-plugin-mdx@3.5.6 β”‚ └── vite@2.5.10 deduped β”œβ”€β”¬ vite-plugin-ruby@3.0.1 β”‚ └── vite@2.5.10 deduped └── vite@2.5.10 ```

Logs πŸ“œ

If not providing a reproduction:

Output _Run `DEBUG=vite-plugin-ruby:* bin/vite dev` or `DEBUG=vite-plugin-ruby:* bin/vite build` and provide the output:_ In this case, I think the output of invoking `resolve_entries` directly is more relevant: I've included that below. Note that the warnings below "rendering chunks" are repeated a few times (the sourcemap warning is repeated a lot). I've omitted the duplicates for readability. I don't think the warnings relevant to this problem, but I'm including them just in case I'm misunderstanding this. (I do intend to investigate and address these but wanted to report this issue now.) ``` [7] pry(main)> ViteRuby.instance.manifest.resolve_entries('application', type: :typescript) Building with Vite ⚑️ vite v2.5.10 building for test... transforming... βœ“ 3004 modules transformed. rendering chunks... Error when using sourcemap for reporting an error: Can't resolve original location of error. Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade` [BABEL] Note: The code generator has deoptimised the styling of /home/maciek/project/node_modules/react-dom/cjs/react-dom.development.js as it exceeds the max of 500KB. [plugin:inject] rollup-plugin-inject: failed to parse /home/maciek/project/app/javascript/styles/global/index.scss. Consider restricting the plugin to particular files via options.include 'unix' is not exported by 'node_modules/moment/dist/moment.js' 'duration' is not exported by 'node_modules/moment/dist/moment.js' <--- Last few GCs ---> [665987:0x62ee0c0] 101065 ms: Mark-sweep (reduce) 2036.0 (2051.9) -> 2034.9 (2054.0) MB, 1709.3 / 0.1 ms (average mu = 0.418, current mu = 0.035) allocation failure scavenge might not succeed [665987:0x62ee0c0] 103846 ms: Mark-sweep (reduce) 2035.3 (2055.0) -> 2035.2 (2055.2) MB, 2412.5 / 0.1 ms (average mu = 0.279, current mu = 0.132) allocation failure GC in old space requested <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 0xa04200 node::Abort() [node] 2: 0x94e4e9 node::FatalError(char const*, char const*) [node] 3: 0xb7978e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 4: 0xb79b07 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 5: 0xd34395 [node] 6: 0xd64f2e v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [node] 7: 0xd70f66 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk*, long*) [node] 8: 0xd5d14f v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [node] 9: 0xd5d3c8 v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [node] 10: 0xd4fca9 v8::internal::ItemParallelJob::Run() [node] 11: 0xd72ec0 void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::MigrationObserver*, long) [node] 12: 0xd7375c v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node] 13: 0xd73925 v8::internal::MarkCompactCollector::Evacuate() [node] 14: 0xd85911 v8::internal::MarkCompactCollector::CollectGarbage() [node] 15: 0xd41c38 v8::internal::Heap::MarkCompact() [node] 16: 0xd43728 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 17: 0xd46b6c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 18: 0xd1524b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node] 19: 0x105b390 v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [node] 20: 0x1401219 [node] Build with Vite failed! ❌ ViteRuby::MissingEntrypointError: Vite Ruby can't find entrypoints/application.ts in public/vite-test/manifest.json or public/vite-test/manifest-assets.json. Possible causes: - The file path is incorrect. - The file is not in the entrypoints directory. - Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths. Visit the Troubleshooting guide for more information: https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting from /home/maciek/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/vite_ruby-3.0.0/lib/vite_ruby/manifest.rb:195:in `missing_entry_error' ```

We found this StackOverflow discussion, set the env var suggested there, and now the build completes.

Screenshots πŸ“·

Provide console or browser screenshots of the problem.

N/A

ElMassimo commented 3 years ago

This might be specific to the fact that the process crashed.

The error message logic will use a more concise message if an error is recorded.

Please provide replication steps that can cause the "build with vite failed" condition to be printed, while at the same time not writing the last build metadata with success: false.

msakrejda commented 3 years ago

I tried to come back to this to debug further, but I moved to a new laptop in the meantime, and can no longer reproduce the issue. I'm going to close this for now, but maybe the info above is useful if someone else hits something similar.