Javascript Node.js-使用PKG创建可执行文件
我在node.js中有一个应用程序,现在我正在尝试创建一个可执行文件来运行该应用程序,而不使用所有项目文件,但在尝试使用Javascript Node.js-使用PKG创建可执行文件,javascript,node.js,express,zeit-pkg,Javascript,Node.js,Express,Zeit Pkg,我在node.js中有一个应用程序,现在我正在尝试创建一个可执行文件来运行该应用程序,而不使用所有项目文件,但在尝试使用pkg()时遇到了问题 在package.json中,我添加了以下内容: "pkg": { "scripts": "public/js/*.js", "assets": [ "views/**/*" ], "targets": "node6" }, 在控制台中,我运行这个命令,在这个过程中没有任何错误,我创建了3个平台可执行文件,pkg index.js--output
pkg
()时遇到了问题
在package.json
中,我添加了以下内容:
"pkg": {
"scripts": "public/js/*.js",
"assets": [
"views/**/*"
],
"targets": "node6"
},
在控制台中,我运行这个命令,在这个过程中没有任何错误,我创建了3个平台可执行文件,pkg index.js--output
当我运行可执行文件时,它启动时没有错误,当我访问浏览器时,它会返回以下错误:
Error: Failed to lookup view "login" in views directory "/snapshot/Picking/views"
at EventEmitter.render (/snapshot/Picking/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/snapshot/Picking/node_modules/express/lib/response.js:1008:7)
at ServerResponse.app.use.res.render (/snapshot/Picking/index.js:0)
at index (/snapshot/Picking/controllers/loginController.js:0)
at Layer.handle [as handle_request] (/snapshot/Picking/node_modules/express/lib/router/layer.js:95:5)
at next (/snapshot/Picking/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/snapshot/Picking/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/snapshot/Picking/node_modules/express/lib/router/layer.js:95:5)
at /snapshot/Picking/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/snapshot/Picking/node_modules/express/lib/router/index.js:335:12)
在index.js中,我有以下行访问视图文件夹:
app.set("views", path.join(__dirname, 'views'));
我怎样才能解决这个问题
谢谢您将资产路径设置为“脚本”,但必须将此路径设置为“资产”,如下所示:
"pkg": {
"assets": [
"views/**/*",
"public/js/*.js"
],
"targets": "node6"
因为node.js文件的“脚本”。你的应用程序找不到前端js文件。你不能使用
app.set(“视图”,path.join(u dirname,“视图”)
因为pkg
正在将视图放在快照目录中,所以项目找不到它
渲染时,必须明确指示视图的位置:
res.render(path.join(__dirname, '..', 'views/index'));