【发布时间】:2020-06-05 04:31:25
【问题描述】:
我有一个使用 Angular 通用 "@nguniversal/express-engine": "^9.1.1" 构建的应用程序。我正在尝试添加服务器端节点画布 ("canvas": "^2.6.1") 以在服务器上呈现某些图像。我不需要此库在客户端可用,因此希望将其从捆绑包中排除。
当尝试使用 npm run dev:ssr 运行应用程序时 - 我收到与该库相关的错误:
ERROR in ./node_modules/canvas/build/Release/canvas.node 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are
configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
this.debug is not a function
经过一些研究,我发现externalDependencies 选项已添加到angular.json 服务器构建选项中。我试图将canvas 库路径添加到externalDependencies 的数组中,但这并没有给出任何结果。错误仍然存在。构建失败。
如果平台是server,目前我正在使用动态import() 将画布库加载到角度服务之一中。出于某种原因,我认为默认情况下它不会尝试捆绑动态导入的脚本。
也许还有其他解决方法。
因此,总而言之,理想情况下,我希望有一个仅在服务器端可用的服务,并且将使用其中的 canvas 库。并且不会破坏角度构建。
【问题讨论】:
标签: angular server-side-rendering angular-universal