无法在 Vue 3 单 Spa 应用程序中读取未定义的属性(读取“元”)
我正在开发一个微前端项目,使用 vue 3 和 single-spa 5.9.3。 我试图将一个微前端 npm 包更新到最新版本,它可以正确构建,但会抛出此错误:
"TypeError: application '@myapp/my-module' died in status LOADING_SOURCE_CODE: Cannot read properties of undefined (reading 'meta')
at autoPublicPath (http://localhost:9200/js/app.js:48439:32)
at Object../node_modules/systemjs-webpack-interop/auto-public-path/2.js (http://localhost:9200/js/app.js:48418:1)
at __webpack_require__ (http://localhost:9200/js/app.js:75668:33)
at http://localhost:9200/js/app.js:76740:11
at Object.<anonymous> (http://localhost:9200/js/app.js:76744:12)
at Object.execute (https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/amd.min.js:1:529)
at i (https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:4539)
at e (https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:5014)
at https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:5019"
我的 '@myapp/my-module' package.json 依赖项如下所示:
"dependencies": {
"core-js": "^3.6.5",
"axios": "^0.24.0",
"object-path": "^0.11.8",
"quasar": "^2.5.5",
"single-spa-vue": "^2.1.0",
"vue": "^3.2.29",
"vue-i18n": "^9.1.6",
"vue-inline-svg": "^3.1.0",
"vue-router": "^4.0.0-0",
"vue-axios": "^3.4.0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vue/cli-plugin-babel": "^5.0.3",
"@vue/cli-plugin-e2e-cypress": "^5.0.3",
"@vue/cli-plugin-eslint": "^5.0.3",
"@vue/cli-plugin-router": "^5.0.3",
"@vue/cli-plugin-typescript": "^5.0.3",
"@vue/cli-plugin-unit-jest": "^5.0.3",
"@vue/cli-plugin-vuex": "^5.0.3",
"@vue/cli-service": "^5.0.3",
"@vue/eslint-config-typescript": "^9.1.0",
"@vue/test-utils": "^2.0.0-0",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-vue": "^8.0.3",
"jest-junit": "^13.0.0",
"sass": "1.32.12",
"sass-loader": "^10.1.0",
"typescript": "~4.5.5",
"vue-cli-plugin-quasar": "~4.0.4",
"vue-cli-plugin-single-spa": "^3.3.0",
"vue-jest": "^5.0.0-alpha.10"
}
以及 single-spa 主项目“root- webpack.config”依赖项和 webpack 配置如下所示:
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@types/systemjs": "^6.1.0",
"babel-eslint": "^11.0.0-beta.2",
"babel-loader": "^8.2.2",
"bootstrap": "5.0.1",
"concurrently": "^5.3.0",
"copy-webpack-plugin": "^8.1.0",
"css-loader": "^6.2.0",
"eslint": "^6.8.0",
"eslint-config-important-stuff": "^1.1.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.4.0",
"html-webpack-plugin": "^5.3.2",
"jest": "^25.4.0",
"jest-cli": "^25.4.0",
"jest-junit": "^13.0.0",
"mini-css-extract-plugin": "^2.2.0",
"prettier": "^2.3.2",
"pretty-quick": "^2.0.2",
"sass": "^1.38.0",
"sass-loader": "^12.1.0",
"serve": "^12.0.0",
"webpack": "^5.51.0",
"webpack-cli": "^4.8.0",
"webpack-config-single-spa": "^5.0.0",
"webpack-dev-server": "^4.0.0",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"loadash": "^1.0.0",
"single-spa": "^5.9.3"
},
webpack.config.js:
const { merge } = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (webpackConfigEnv, argv) => {
const orgName = "myapp";
const defaultConfig = singleSpaDefaults({
orgName,
projectName: "root-config",
webpackConfigEnv,
argv,
disableHtmlGeneration: true,
});
return merge(defaultConfig, {
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: "src/index.ejs",
templateParameters: {
isLocal: webpackConfigEnv && webpackConfigEnv.isLocal,
orgName,
},
}),
new MiniCssExtractPlugin({
filename: "css/style.css",
}),
new CopyWebpackPlugin({
patterns: [
{
from: "./src/assets",
to: "./assets",
},
{
from: "./src/config",
to: "./config",
},
{
from:"favicon.ico",
to: "favicon.ico",
},
{
from:"staticwebapp.config.json",
to:"staticwebapp.config.json"
}
],
}),
],
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: {
implementation: require("sass"),
},
},
],
},
],
},
externals: ["single-spa", "vue", "vue-router", "vuex", /^@myapp\/.+$/],
});
};
看起来 webpack v5 和 v4 版本之间存在问题,但从该方面没有明显的问题需要修复。
I am working on a micro-frontend project, using vue 3 and single-spa 5.9.3.
I was trying to update one Micro-frontend npm packages to recent releases, it builds correctly but throws this error:
"TypeError: application '@myapp/my-module' died in status LOADING_SOURCE_CODE: Cannot read properties of undefined (reading 'meta')
at autoPublicPath (http://localhost:9200/js/app.js:48439:32)
at Object../node_modules/systemjs-webpack-interop/auto-public-path/2.js (http://localhost:9200/js/app.js:48418:1)
at __webpack_require__ (http://localhost:9200/js/app.js:75668:33)
at http://localhost:9200/js/app.js:76740:11
at Object.<anonymous> (http://localhost:9200/js/app.js:76744:12)
at Object.execute (https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/amd.min.js:1:529)
at i (https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:4539)
at e (https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:5014)
at https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js:4:5019"
my '@myapp/my-module' package.json dependencies looks like this:
"dependencies": {
"core-js": "^3.6.5",
"axios": "^0.24.0",
"object-path": "^0.11.8",
"quasar": "^2.5.5",
"single-spa-vue": "^2.1.0",
"vue": "^3.2.29",
"vue-i18n": "^9.1.6",
"vue-inline-svg": "^3.1.0",
"vue-router": "^4.0.0-0",
"vue-axios": "^3.4.0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vue/cli-plugin-babel": "^5.0.3",
"@vue/cli-plugin-e2e-cypress": "^5.0.3",
"@vue/cli-plugin-eslint": "^5.0.3",
"@vue/cli-plugin-router": "^5.0.3",
"@vue/cli-plugin-typescript": "^5.0.3",
"@vue/cli-plugin-unit-jest": "^5.0.3",
"@vue/cli-plugin-vuex": "^5.0.3",
"@vue/cli-service": "^5.0.3",
"@vue/eslint-config-typescript": "^9.1.0",
"@vue/test-utils": "^2.0.0-0",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-vue": "^8.0.3",
"jest-junit": "^13.0.0",
"sass": "1.32.12",
"sass-loader": "^10.1.0",
"typescript": "~4.5.5",
"vue-cli-plugin-quasar": "~4.0.4",
"vue-cli-plugin-single-spa": "^3.3.0",
"vue-jest": "^5.0.0-alpha.10"
}
and the single-spa main project "root-config" dependencies and webpack config looks like this:
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@types/systemjs": "^6.1.0",
"babel-eslint": "^11.0.0-beta.2",
"babel-loader": "^8.2.2",
"bootstrap": "5.0.1",
"concurrently": "^5.3.0",
"copy-webpack-plugin": "^8.1.0",
"css-loader": "^6.2.0",
"eslint": "^6.8.0",
"eslint-config-important-stuff": "^1.1.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.4.0",
"html-webpack-plugin": "^5.3.2",
"jest": "^25.4.0",
"jest-cli": "^25.4.0",
"jest-junit": "^13.0.0",
"mini-css-extract-plugin": "^2.2.0",
"prettier": "^2.3.2",
"pretty-quick": "^2.0.2",
"sass": "^1.38.0",
"sass-loader": "^12.1.0",
"serve": "^12.0.0",
"webpack": "^5.51.0",
"webpack-cli": "^4.8.0",
"webpack-config-single-spa": "^5.0.0",
"webpack-dev-server": "^4.0.0",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"loadash": "^1.0.0",
"single-spa": "^5.9.3"
},
webpack.config.js:
const { merge } = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (webpackConfigEnv, argv) => {
const orgName = "myapp";
const defaultConfig = singleSpaDefaults({
orgName,
projectName: "root-config",
webpackConfigEnv,
argv,
disableHtmlGeneration: true,
});
return merge(defaultConfig, {
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: "src/index.ejs",
templateParameters: {
isLocal: webpackConfigEnv && webpackConfigEnv.isLocal,
orgName,
},
}),
new MiniCssExtractPlugin({
filename: "css/style.css",
}),
new CopyWebpackPlugin({
patterns: [
{
from: "./src/assets",
to: "./assets",
},
{
from: "./src/config",
to: "./config",
},
{
from:"favicon.ico",
to: "favicon.ico",
},
{
from:"staticwebapp.config.json",
to:"staticwebapp.config.json"
}
],
}),
],
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: {
implementation: require("sass"),
},
},
],
},
],
},
externals: ["single-spa", "vue", "vue-router", "vuex", /^@myapp\/.+$/],
});
};
it looks like there is an issue between webpack v5 and v4 versions, but there is no obvious problem to fix from that side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在迁移到 webpack 5 和 vue-cli-plugin-single-spa v3.3.0 时遇到了同样的问题。在您的个人应用程序中,您需要在 vue.config.js 中设置一个字段:
我不确定您是否也需要在 webpack.config.js 中设置此字段:
I had the same issue migrating to webpack 5 and vue-cli-plugin-single-spa v3.3.0. In your individual application you need to set a field in the vue.config.js:
I'm not sure if you also need this in your webpack.config.js: