nikushi / minipack

Minipack, a gem for minimalists, which can integrates Rails with webpack. It is an alternative to Webpacker.
MIT License
115 stars 22 forks source link

Sprockets::Rails::Helper::AssetNotFound at / #26

Closed anitagraham closed 4 years ago

anitagraham commented 4 years ago

I am trying to use Minipack but I am getting this error:

Sprockets::Rails::Helper::AssetNotFound at /
The asset "js/vendors-home.adac56fa84f3069d8f77.js" is not present in the asset pipeline

The asset mentioned is generated by webpack, and can be found in public/dist/js. However, I do have assets from the asset pipeline - notably from other gems. . Configuration information below. Does anything stick out as obviously wrong. In the meantime I have begun a clean new app to see if I can get it working there.

thanks,

Anita

Bundle generation

// webpack.dev.js
const commonConfig = require('./webpack.common.js');
const finalPath =  path.resolve(paths.Public, 'dist');

const devConfig = {
  mode: 'development',
  output: {
    path: finalPath,
    filename: 'js/[name].[chunkhash].js'
  },
....
module.exports = merge(commonConfig, devConfig)
//webpack.common.js
...
const commonConfig = {
 plugins: [
    new WebpackAssetsManifest({
      entrypoints: true
    }),
...

...
module.exports = commonConfig

Files are generated in public/dist and look fine.

# manifest.json
...
 "entrypoints": {
    "home": {
      "js": [
        "js/vendors-home.adac56fa84f3069d8f77.js",
        "js/home.4349e22ee3d91d252be1.js"
      ],
      "css": [
        "css/home.4d19c4ae13baa692fc23.css"
      ]
    }
  },
  "home.css": "css/home.4d19c4ae13baa692fc23.css",
  "home.js": "js/home.4349e22ee3d91d252be1.js",
  "vendors-home.js": "js/vendors-home.adac56fa84f3069d8f77.js"
...

Bundle consumption

# config/minipack.rb
Minipack.configuration do |c|
  c.cache = !Rails.env.development?
  c.manifest = Rails.root.join("public", "dist", "manifest.json")
end

and finally in the view

<!-- Javascript/Stylesheet Pack Tag-->
<%= javascript_bundles_with_chunks_tag 'home', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_bundles_with_chunks_tag 'home', 'data-turbolinks-track': 'reload' %>
<!-- Javascript/Stylesheet Pack Tag-->

and it is from here that the error is triggered.

anitagraham commented 4 years ago

I've generated a much simpler app, without all the baggage of the original one, and I am getting the same error.

Rails 6.0.0 (original problem on Rails 5.2.3) Ruby 2.6.3

nikushi commented 4 years ago

The configuration looks no problem. I’ll check it in a few days.

anitagraham commented 4 years ago

Solution so far - in the simplified application is

# config/environments/development.rb
config.assets.check_precompiled_asset = false

and

# config/initializers/assets.rb
# Add the webpack output path to the assets path
Rails.application.config.assets.paths += [
  Rails.root.join('public', 'dist' ).to_s
]

I'll close the issue, but if there is a better answer I'd be eager to see it.