Skip to content
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

使用normalize.css时服务端渲染会报错 #15

Open
funkyLover opened this issue Mar 11, 2020 · 4 comments
Open

使用normalize.css时服务端渲染会报错 #15

funkyLover opened this issue Mar 11, 2020 · 4 comments

Comments

@funkyLover
Copy link

// app/web/framework/app.ts
import 'normalize.css';
2020-03-11 17:47:29,461 ERROR 58250 [admin/home.js] server render bundle error, try client render, the server render error //egg-vue-typescript-boilerplate/node_modules/normalize.css/normalize.css:11
html {
     ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/funkyLover/Desktop/egg-vue-typescript-boilerplate/node_modules/ts-node/src/index.ts:431:14)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at r (/Users/funkyLover/Desktop/egg-vue-typescript-boilerplate/node_modules/vue-server-renderer/build.dev.js:9310:16)
    at eval (webpack:///external_%22normalize.css%22?:1:18)
    at Object.normalize.css (__vue_ssr_bundle__:1069:1)
    at __webpack_require__ (__vue_ssr_bundle__:26:30)
    at eval (webpack:///./app/web/framework/app.ts?:6:71)
    at Module../app/web/framework/app.ts (__vue_ssr_bundle__:368:1)
    at __webpack_require__ (__vue_ssr_bundle__:26:30)
    at eval (webpack:///./app/web/page/admin/home/index.ts?:2:72)
@funkyLover
Copy link
Author

这里还有个新的问题,如果去掉 normalize.css 依然会报错

2020-03-11 17:56:53,392 ERROR 55180 [admin/home.js] server render bundle error, try client render, the server render error ReferenceError: document is not defined
    at eval (webpack:///./node_modules/vue-echarts/dist/vue-echarts.js?:1:11870)
    at eval (webpack:///./node_modules/vue-echarts/dist/vue-echarts.js?:1:37)
    at eval (webpack:///./node_modules/vue-echarts/dist/vue-echarts.js?:1:138)
    at Object../node_modules/vue-echarts/dist/vue-echarts.js (__vue_ssr_bundle__:2697:1)
    at __webpack_require__ (__vue_ssr_bundle__:20:30)
    at eval (webpack:///./app/web/component/common/echart/index.ts?./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/thread-loader/dist/cjs.js??ref--0-1!./node_modules/ts-loader??ref--0-2:6:86)
    at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/thread-loader/dist/cjs.js?!./node_modules/ts-loader/index.js?!./app/web/component/common/echart/index.ts?vue&type=script&lang=ts& (__vue_ssr_bundle__:1391:1)
    at __webpack_require__ (__vue_ssr_bundle__:20:30)
    at eval (webpack:///./app/web/component/common/echart/index.ts?:2:225)
    at Module../app/web/component/common/echart/index.ts?vue&type=script&lang=ts& (__vue_ssr_bundle__:227:1)

这里看似是 vue-echarts 导致的

因为 vue-echarts的文档中指出 webpack 环境下默认提供的是源码版本,所以需要配置babel处理

但是来到 easywebpack 中不知道应该如何修改对应配置以做到之前的配置不被破坏的情况下增加新的配置😅

所以我在引入的时候是这样引用的

import ECharts from 'vue-echarts/dist/vue-echarts';

虽然客户端渲染能跑通但是服务端渲染会报错

@hubcarl
Copy link
Collaborator

hubcarl commented Mar 14, 2020

@funkyLover 从错误看,vue-echarts 不支持 ssr , 具体解决方案 https://www.yuque.com/easy-team/blog/lcbfwb

@funkyLover
Copy link
Author

@hubcarl 感谢,那第一个问题方便帮忙看下吗

import 'normalize.css';

@hubcarl
Copy link
Collaborator

hubcarl commented Jul 22, 2020

直接在 .vue 页面里面 import 'normalize.css' 试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants