middleman / middleman

Hand-crafted frontend development

Home Page:https://middlemanapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

asset_hash plugin removes relative path specifier, breaking ES modules

marcoms opened this issue · comments

Expected behavior and actual behavior

ES modules don't allow module specifiers that don't have a slash as shown below:

Uncaught TypeError: Failed to resolve module specifier "chunk-3LNNNTUA-fcaa17b4.js". Relative references must start with either "/", "./", or "../".

This comes from my JS bundle which begins with:

import{a as z,b as se,c as Eo,d as G,e as je,f as ue}from"./chunk-3LNNNTUA.js";

But gets replaced with this by asset_hash:

import{a as z,b as se,c as Eo,d as G,e as je,f as ue}from"chunk-3LNNNTUA-fcaa17b4.js";

It's important the ./ is preserved as shown by the above error.

Additional information

  • Ruby version: 3.0.0
  • Middleman version: 4.x branch

Hi @marcoms 👋🏼 not sure if this is going to help with your problem or it's even related, but just in case ...

Couple of days ago I raised this issue: #2530. The point is that the current JavaScript minifier (only in v4 branch, in master is already changed to Terser) relies on the Uglifier gem, which doesn't support well ES6 syntax. So maybe your problem is somehow related? This only applies if you are using the :minify_javascript setting of course. The :asset_hash extension is a different one, but since I got some different problems due to Uglifier maybe it's worth a try 🤷

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hello @marcoms 👋🏼

Could you please try running your site under current main branch?

 gem "middleman", git: "https://github.com/middleman/middleman.git"

We pushed some fixes in the last months, so maybe this is gone.