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

请问可以在nestJS中配置art-template吗? #647

Open
123lujiaqiang opened this issue Jul 25, 2022 · 1 comment
Open

请问可以在nestJS中配置art-template吗? #647

123lujiaqiang opened this issue Jul 25, 2022 · 1 comment

Comments

@123lujiaqiang
Copy link

No description provided.

@houkunlin
Copy link

我最近尝试用 nestJs 来写一个小服务(群晖NAS短信通知、WebHooks中转服务),主要就是用来简单的解析一些模板内容,因此引入了 art-template ,但是并没有使用 art-template 来渲染HTML页面内容。

在我打包的计划发布到生产环境的时候,先是解决了 nestJs 包含依赖的打包问题后,运行的时候遇到了 art-template 的引入问题,以下是我的记录内容:

npm run build

打包成功后会生成一个 ./dist/main.js 文件,此时可使用命令 node ./dist/main.js 运行服务,不出意外的话会出现一个异常信息

/home/user/http-server-node/dist/main.js:229652
(void 0)[template.defaults.extname] = extension;
                                    ^

TypeError: Cannot set properties of undefined (setting '.art')
    at Object.<anonymous> (/home/user/http-server-node/dist/main.js:229652:37)
    at __webpack_require__ (/home/user/http-server-node/dist/main.js:271956:42)
    at Object.<anonymous> (/home/user/http-server-node/dist/main.js:57762:21)
    at __webpack_require__ (/home/user/http-server-node/dist/main.js:271956:42)
    at Object.<anonymous> (/home/user/http-server-node/dist/main.js:57689:26)
    at __webpack_require__ (/home/user/http-server-node/dist/main.js:271956:42)
    at Object.<anonymous> (/home/user/http-server-node/dist/main.js:19:22)
    at __webpack_require__ (/home/user/http-server-node/dist/main.js:271956:42)
    at /home/user/http-server-node/dist/main.js:272020:37
    at Object.<anonymous> (/home/user/http-server-node/dist/main.js:272022:12)

这个异常是 art-template 模板引擎导致的,art-template 中有一行代码打包后无法在 node 下执行,此时需要魔改 art-template 代码,改动文件 node_modules/art-template/index.js ,原代码如下:

const template = require('./lib/index');
const extension = require('./lib/extension');

template.extension = extension;
require.extensions[template.defaults.extname] = extension;

module.exports = template;

改动后的代码

const template = require('./lib/index');
const extension = require('./lib/extension');

template.extension = extension;
// require.extensions[template.defaults.extname] = extension;// 只需要注释掉这行代码就行了

module.exports = template;

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