-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
running bundle created with esbuild results in Invalid asm.js: Type mismatch in assignment
#856
Comments
I didn't design esbuild to be able to handle asm.js. The reason why it isn't valid asm.js without the minify flag is that
This is only a warning, not a failure. The bundled code should still work. The whole design of asm.js is based around it just being JavaScript so if it doesn't validate or if the VM doesn't know anything about asm.js it should still work fine. One option could be for you to just ignore V8's warning. I don't think encoding asm.js-specific logic into esbuild is a good idea. There are many complicated validation rules for asm.js (it has its own type system) and it's basically just a legacy format that was mainly useful for convincing standards committees that WebAssembly was a good idea. Now everyone is using WebAssembly instead, which is superior in pretty much every way. The asm.js format is quickly getting less and less relevant. The most straightforward "fix" for this I can think of is for esbuild to just always remove the If this being asm.js is important to you and you still want to use esbuild, you could use a plugin to ensure that the content is passed through as a string. I hacked this plugin together and it seems to work: require('esbuild').build({
entryPoints: ['x509.js'],
bundle: true,
platform: 'node',
outfile: './out.js',
plugins: [{
name: 'asm.js-fix',
setup(build) {
build.onResolve({ filter: /em-x509/ }, args => {
return {
path: require.resolve(args.path, { paths: [args.resolveDir] }),
namespace: 'wrap-in-string',
}
})
build.onLoad({ filter: /.*/, namespace: 'wrap-in-string' }, async (args) => {
return {
contents: `
eval(${JSON.stringify(await require('fs').promises.readFile(args.path, 'utf8'))})
return module.exports
`,
}
})
},
}],
}).then(() => {
console.log('result:', require('./out.js'))
}) |
Oh I wonder if this was the actual cause of vadimdemedes/ink#415. I worked around this issue like this: // TODO: remove this when https://github.com/vadimdemedes/ink/issues/415 is resolved.
const _disableWarning = process.emitWarning;
process.emitWarning = () => {};
const { renderConfirm } = require(CONFIRM_PROMPT_PATH);
process.emitWarning = _disableWarning; |
@evanw thanks for the quick & detailed feedback. honestly, i don't care about i am surprised that this popped up when it used to work without any warnings for a while now (i only noticed when my personal web server did not renew it's certificate automatically).
maybe it would be if i didn't run my apps in strict mode :) @Jarred-Sumner that seems like nasty hack, but i might keep it at hand for future usage :) in any case, this feedback is sufficient to close the issue. |
i have a simple project that used to work, but now fails with
Invalid asm.js: Type mismatch in assignment
after bundling it with esbuild.Note that running non-bundled code works fine, it's only running bundled code that fails.
running code directly:
esbuild --outdir=dist --target=es2018 --platform=node --format=cjs --color=true --log-level=error --bundle src/piacme.js
running bundled code:
however, if i enable
--minify
esbuild flag, it works!this must be first time where non-minified code fails and minified works...
project code (it's a single source file) is at https://github.com/vladmandic/piacme
i don't know which upgrade broke it as it's been a while since i've last checked, it could be esbuild itself, included module x509.js or newer nodejs.
environment: nodejs 15.7.0 on ubuntu 20.10 with esbuild 0.8.49
The text was updated successfully, but these errors were encountered: