17:51 2024/11/15
使用pkg打包express node的时候提示错误:
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call.
2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
通过尝试,在app.js 中不能包含绝对路径,只能是相对路径
//const fs = require('fs');
//const path = require('path');
//const basename = path.basename(__filename);
// view engine setup
//app.set('views', path.join(__dirname, 'views'));
//app.set('views', path.join(process.cwd(), 'views'));
//app.set('views', process.cwd() + '/views');
app.set('views','views');
//app.use(express.static(path.join(__dirname, 'public')));
//app.use(express.static(path.join(process.cwd(), 'public')));
//app.use(express.static(path.join('./'/*__dirname*/, 'public')));
//app.use(express.static(process.cwd() + '/public'));
app.use(express.static( 'public'));
只有最后一个才是正确的。
1869

被折叠的 条评论
为什么被折叠?



