遇到报错render error TypeError: Cannot read property 'file' of undefined

来源:5-3 服务端渲染的entry配置

Junble

2021-04-12

老师你好,我遇到报错render error TypeError: Cannot read property ‘file’ of undefined

npm run dev:server

> vue-ssr-tech@1.0.0 dev:server D:\projects\new\vue-ssr-tech
> cross-env NODE_ENV=development node server/server.js

server is listening on 0.0.0.0:3333
(node:24128) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications 
are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)
new bundle generated
request with path /
{ url: '/' }
my store plugin invoked
todo before enter
render error TypeError: Cannot read property 'file' of undefined
    at D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9074:24
    at Array.map (<anonymous>)
    at TemplateRenderer.renderScripts (D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9072:19)       
    at module.exports (D:\projects\new\vue-ssr-tech\server\routers\server-render.js:15:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async handleSSR (D:\projects\new\vue-ssr-tech\server\routers\dev-ssr.js:54:3)
    at async D:\projects\new\vue-ssr-tech\server\server.js:12:5
TypeError: Cannot read property 'file' of undefined
    at D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9074:24
    at Array.map (<anonymous>)
    at TemplateRenderer.renderScripts (D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9072:19)       
    at module.exports (D:\projects\new\vue-ssr-tech\server\routers\server-render.js:15:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async handleSSR (D:\projects\new\vue-ssr-tech\server\routers\dev-ssr.js:54:3)
    at async D:\projects\new\vue-ssr-tech\server\server.js:12:5
request with path /favicon.ico
{ url: '/favicon.ico' }
my store plugin invoked
render error TypeError: Cannot read property 'file' of undefined
    at D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9074:24
    at Array.map (<anonymous>)
    at TemplateRenderer.renderScripts (D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9072:19)       
    at module.exports (D:\projects\new\vue-ssr-tech\server\routers\server-render.js:15:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async handleSSR (D:\projects\new\vue-ssr-tech\server\routers\dev-ssr.js:54:3)
    at async D:\projects\new\vue-ssr-tech\server\server.js:12:5
TypeError: Cannot read property 'file' of undefined
    at D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9074:24
    at Array.map (<anonymous>)
    at TemplateRenderer.renderScripts (D:\projects\new\vue-ssr-tech\node_modules\vue-server-renderer\build.dev.js:9072:19)       
    at module.exports (D:\projects\new\vue-ssr-tech\server\routers\server-render.js:15:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async handleSSR (D:\projects\new\vue-ssr-tech\server\routers\dev-ssr.js:54:3)
    at async D:\projects\new\vue-ssr-tech\server\server.js:12:5

我的项目github地址:
https://github.com/greetfish/my_vue_learning
第4个commit是关于这个问题的
第2个commit是关于head中的内容在body里面出现那个问题
https://coding.imooc.com/learn/questiondetail/L0ZxAYWmDpn65zln.html

请帮我看一下

写回答

1回答

Junble

提问者

2021-04-13

该问题解决了,我调试node_modules/vue-server-renderer/build.dev.js

将9070行改为

    // var needed = [initial[0]].concat(async, initial.slice(1));

    var needed = (initial.length ? [initial[0]] : []).concat(async, initial.slice(1));


1
1
Jokcy
好的,赞
2021-04-14
共1条回复

Vue核心技术 Vue+Vue-Router+Vuex+SSR实战精讲

深入讲解Vue核心技术,展示Vue应用开发中的各种问题和解决方案

3168 学习 · 853 问题

查看课程