main.js
(添加了async beforeCreate()
):
/* main.js */ 從“vue”導(dǎo)入 Vue 從“./App.vue”導(dǎo)入應(yīng)用程序 Vue.config.生產(chǎn)提示 = false 新的Vue({ 渲染:h => h(應(yīng)用程序), 異步 beforeCreate() { const wlib=等待導(dǎo)入('my-webasm-lib') 控制臺(tái).log(wlib) }, }).$mount('#app'); <p>在 <code>npm runserve模塊解析失敗:意外字符 '' (1:0) 該模塊似乎是一個(gè) WebAssembly 模塊,但該模塊未標(biāo)記為 webpack 的 WebAssembly 模塊。 重大更改:由于 webpack 5 WebAssembly 默認(rèn)情況下未啟用并被標(biāo)記為實(shí)驗(yàn)性功能。 您需要通過(guò)“experiments.asyncWebAssembly: true”(基于異步模塊)或“experiments.syncWebAssembly: true”(如 webpack 4,已棄用)啟用 WebAssembly 實(shí)驗(yàn)之一。 對(duì)于轉(zhuǎn)換為 WebAssembly 的文件,請(qǐng)確保在配置的“module.rules”部分設(shè)置模塊類型(例如“type:”webassemble/async”)。 (此二進(jìn)制文件省略源代碼) <p><strong>如何修復(fù)?</strong></p> <p>我嘗試將上述配置添加到 <code>webpack.config.js</code> 中,正如所說(shuō)的那樣,但沒(méi)有成功:</p>
module.exports = { 實(shí)驗(yàn):{ asyncWebAssembly:正確, 導(dǎo)入異步:真 } }</pre> <p>我的<code>package.json</code> 如果如下:</p>... “依賴項(xiàng)”:{ "core-js": "^3.8.3", "my-webasm-lib": "文件:../my-webasm-lib/my-webasm-lib-pkg", “vue”:“^2.6.14” }, “開(kāi)發(fā)依賴項(xiàng)”:{ "@babel/core": "^7.12.16", "@babel/eslint-parser": "^7.12.16", "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-service": "~5.0.0", "eslint": "^7.32.0", "eslint-plugin-vue": "^8.0.3", “vue-模板編譯器”:“^2.6.14” }, ...</pre> <p><br />></p>
回答有點(diǎn)晚了,但也許對(duì)某人有幫助。
module.exports = { runtimeCompiler: true, configureWebpack: { externals: { experiments: { asyncWebAssembly: true, }, }, }, };