Reputation: 1929
I have an application in node.js and now I'm trying to create a executable to run the application without all project files but I'm having problems when I try use pkg
(https://github.com/zeit/pkg#detecting-assets-in-source-code).
In package.json
I add this:
"pkg": {
"scripts": "public/js/*.js",
"assets": [
"views/**/*"
],
"targets": "node6"
},
In console I run this command and I don't have any error in this process and create 3 platforms executable, pkg index.js --output
When I run the executable It starts with no errors and when I access to browser it returns me this error:
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)
In index.js I have this line to access views folder:
app.set("views", path.join(__dirname, 'views'));
How can I solve this situation?
Thank you
Upvotes: 0
Views: 2871
Reputation: 4355
You can't use app.set("views", path.join(__dirname, 'views'));
because pkg
is placing your views in the snapshot directory, so your project won't find it.
You have to explicitly indicate where your views are when rendering:
res.render(path.join(__dirname, '..', 'views/index'));
Upvotes: 0
Reputation: 717
You set your assets path into "scripts", but you must set this path to "assets", like this:
"pkg": {
"assets": [
"views/**/*",
"public/js/*.js"
],
"targets": "node6"
because "scripts" for node.js files. And your app not found frontend js-files.
Upvotes: 0