vue ssr error: TypeError: Cannot read property 'replace' of undefined
在开发vue ssr应用时, yarn build yarn start 之后启动正常:
info Server running at: http://0.0.0.0:6606
在访问页面时,发现页面降级到SPA,服务端报错:
debug Server rendering encountered an error: { TypeError: Cannot read property 'replace' of undefined }
经过排查,错误出在 vue-server-renderer(v2.6.11) 中:
9081 TemplateRenderer.prototype.getUsedAsyncFiles = function getUsedAsyncFiles (context) {
9082 if (!context._mappedFiles && context._registeredComponents && this.mapFiles) {
9083 var registered = Array.from(context._registeredComponents);
9084 context._mappedFiles = this.mapFiles(registered).map(normalizeFile);
9085 }
9086 return context._mappedFiles
9087 };
原因是 this.mapFiles(registered) 中没有匹配到css的sourcemap文件
修改源码过滤掉 undefined 可以解决报错(错误示范)
可以修改 vue.config.js 配置文件(项目由vue cli3/4创建):
module.exports = {
+ css: {
+ extract: true,
+ sourceMap: true
+ }
};
为css启用sourcemap就行了,问题解决。记得重新build
vue ssr error: TypeError: Cannot read property 'replace' of undefined的更多相关文章
- underscore.js定义模板遇到问题:Uncaught TypeError: Cannot read property 'replace' of undefined
代码正确缩进位置如下, extend "layout" block 'content',-> div ->'nihao' script id:"Invoice ...
- vue报错TypeError: Cannot read property 'protocol' of undefined
错误信息如下所示: isURLSameOrigin.js?3934:57 Uncaught (in promise) TypeError: Cannot read property 'protocol ...
- Appium dmg 安装:[TypeError: Cannot read property 'replace' of undefined]
问题原因:appium dmg 版本没有默认node.js 解决方案:安装稳定版的node.js.(官网下载安装即可.) 验证:命令行输入:node -v 查看版本号 npm -v 查看版本号
- vue报错TypeError: Cannot read property '$createElement' of undefined
报错截图: 这个错误就是路由上的component写成了components
- ngzorro draw 第一次打开 ERROR TypeError: Cannot read property 'overlayElement' of undefined
at NzDrawerComponent.push../node_modules/ng-zorro-antd/fesm5/ng-zorro-antd.js.NzDrawerComponent.trap ...
- TypeError: Cannot read property 'compilation' of undefined
Vue build失败 TypeError: Cannot read property 'compilation' of undefined 1. 使用npm run build 失败 使用npm ...
- Vue使用Typescript开发编译时提示“ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'afterCompile' of undefined”的解决方法
使用Typescript开发Vue,一切准备就绪.但npm start 时,提示“ ERROR in ./src/main.tsModule build failed: TypeError: Cann ...
- [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined、vuejs路由使用的问题Error in render function
1.[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined 注意,只要出现Error i ...
- SharePoint 2013 Error - TypeError: Unable to get property 'replace' of undefined or null reference
错误信息 TypeError: Unable to get property ‘replace’ of undefined or null referenceTypeError: Unable to ...
- vue v-if:"TypeError: Cannot read property 'length' of undefined"
在使用v-if判断一个数组大小为0时,会出现 length 是undefined的错误:[Vue warn]: Error in render: "TypeError: Cannot rea ...
随机推荐
- jsoncpp安装与使用 cmake安装 升级g++ gcc支持c++11
来了新公司之后,现在的json解析真的很难用,举个例子,假如想删除一个对象,要重新生成,去掉要删除的,其余的要组装上.很怀念之前用的jsoncpp,想引进来,就研究一下. 下载和安装 下载 从gith ...
- C++ STL set/multiset容器
set/multiset容器 简介 Set的特性是,所有元素都会根据元素的值自动被排序.Set不允许两个元素有相同的值. Set的迭代器iterator是一种const_iterator,不能通过迭代 ...
- kaggle入门 随机森林求解Titanic
# kaggle Titanic # 导入需要的库 import pandas as pd import numpy as np import sys import sklearn import ra ...
- string的find()与npos
在 C++ 中,std::string::find() 是一个用于在字符串中查找子字符串或字符的成员函数.查找成功时返回匹配的索引位置,查找失败时返回 std::string::npos,表示未找到. ...
- 利用cv2.dilate对图像进行膨胀
cv2.getStructuringElement(cv2.MORPH_RECT, (7,7))介绍,请看这个博客.我简要说一下cv2.getStructuringElement,可用于构造一个特定大 ...
- 宝塔部署java后端项目
1. 安装插件 宝塔面板找到软件商店然后搜索 Java java项目管理安装 安装后点击设置准备安装 tomcat 2. 添加项目
- 一、Spring Boot集成Spring Security专栏
一.Spring Boot集成Spring Security专栏 一.Spring Boot集成Spring Security之自动装配 二.实现功能及软件版本说明 使用Spring Boot集成Sp ...
- Kali Linux 更新 一条命令搞定
Kali Linux 更新 一条命令搞定 sudo apt-get update && sudo apt-get upgrade && sudo apt-get dis ...
- jenkins + sonar 实现代码检测的配置
一.首先安装sonar scanner的客户端 我的jenkins版本为2.176.2 安装sonar需要安装客户端和服务端,这里只讲述客户端的相关配置.安装步骤省略 二.然后配置sonar scan ...
- SQL语法-列的新增、删除
MySQL的语法: 新增列 ALTER TABLE `xxdb`.`xxtable` ADD COLUMN `xx_flag` varchar(1) NULL; 删除列 ALTER TABLE `xx ...