Skip to content

Conversation

@mho22
Copy link
Collaborator

@mho22 mho22 commented Jan 6, 2026

Motivation for the change, related issues

Fixing follow-up issue #3085

I previously removed the Vite extension for External Dynamic Imports thinking it was no longer necessary to fix the issue initiated by the per-PHP-package split pull request. I was wrong. This pull request re-creates the plugin but modifies the behavior to fix the current issue.

The current issue returns this :

Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "./lib/extensions/intl/shared/icu.dat"

    node_modules/@php-wasm/web/index.js:2269:88:
      2269 │ ...wait import("./lib/extensions/intl/shared/icu.dat")).default,...
           ╵                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Implementation details

Re-create the vite-external-dynamic-imports file but :

    regex: /icu\.dat$/,
-    transform: (specifier) =>
-	`./${specifier.split('/').slice(-2).join('/')}`,
+    transform: (specifier) => `../../../${specifier}`,
},

Testing Instructions (or ideally a Blueprint)

CI

@mho22 mho22 added [Type] Bug An existing feature does not function as intended [Package][@php-wasm] Web [Aspect] Internationalization (i18n) labels Jan 6, 2026
@mho22 mho22 requested a review from bgrgicak January 6, 2026 11:42
@mho22
Copy link
Collaborator Author

mho22 commented Jan 6, 2026

@bgrgicak Sorry for the mistake. I should find a way to add a test for this but at the moment it crashes @php-wasm/web when running it in the browser. I guess we should already merge this and release a new set of packages.

@mho22 mho22 requested a review from brandonpayton January 7, 2026 17:06
@brandonpayton
Copy link
Member

@mho22 how can this error be reproduced? I enabled the "intl" in a test site Blueprint and am not encountering any error?

@mho22
Copy link
Collaborator Author

mho22 commented Jan 8, 2026

@brandonpayton This is probably why we didn't catch it as soon as the new packages were released. Here is a test project :

package.json

{
  "type": "module",
  "dependencies": {
    "@php-wasm/web": "^3.0.39",
    "vite": "^7.3.0"
  },
  "scripts": {
    "dev": "vite"
  }
}

vite.config.js

import { defineConfig } from 'vite';


export default defineConfig( {
	assetsInclude: [/\.dat$/, /\.wasm$/, /\.so$/, /\.la$/],
    optimizeDeps : {
		esbuildOptions : {
			loader : {
				'.dat': 'text',
				'.wasm': 'text',
				'.so': 'text',
				'.la': 'text',
			}
		}
	}
} );

index.html

<!DOCTYPE html>

<html>
    <head>
        <script type="module" src="script.js"></script>
    </head>

    <body>
    </body>

</html>

script.js

import { PHP } from '@php-wasm/universal';
import { loadWebRuntime } from "@php-wasm/web";

const php = new PHP( await loadWebRuntime( '8.4' ) );

const response = await php.runStream( { code : `<?php echo "Hello World";` } );

console.log( await response.stdoutText );

Then run

npm install && npm run dev

It then returns :

added 137 packages, and audited 138 packages in 12s

22 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

> dev
> vite


  VITE v7.3.1  ready in 235 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
✘ [ERROR] Could not resolve "./lib/extensions/intl/shared/icu.dat"

    node_modules/@php-wasm/web/index.js:2269:88:
      2269 │ ... "intl.so", n = "icu.dat", s = await nt(i), a = (await import("./lib/extensions/intl/shared/icu.dat")).default, [_, S] = await Promise.all([
           ╵                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/mho/Work/projects/intl/test/node_modules/esbuild/lib/main.js:1467
  let error = new Error(text);
              ^

Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "./lib/extensions/intl/shared/icu.dat"

    node_modules/@php-wasm/web/index.js:2269:88:
      2269 │ ...wait import("./lib/extensions/intl/shared/icu.dat")).default,...
           ╵                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    at failureErrorWithLog (/Users/mho/Work/projects/intl/test/node_modules/esbuild/lib/main.js:1467:15)
    at /Users/mho/Work/projects/intl/test/node_modules/esbuild/lib/main.js:926:25
    at /Users/mho/Work/projects/intl/test/node_modules/esbuild/lib/main.js:1345:9
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

Node.js v22.21.1

@brandonpayton
Copy link
Member

@brandonpayton This is probably why we didn't catch it as soon as the new packages were released. Here is a test project :

Thanks, @mho22, that helps!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants