I have an express API application where the POST routes will upload files into the directory structure temporarily. The files are uploaded into a folder called /uploads. In my code I have the following line:
const filePathToMedia = path.join(__dirname, `../uploads/${apiFile}`);
which from my understanding of the documentation should auto-detect or infer that this directory /uploads should be included with the pkg when generating the executable.
However this doesn't appear to be happening. I get the following error when testing the POST route of my API:
message:
'Error: form-data: File or directory \'C:\\**\\app-name\\uploads\\test.wav\' was not included into executable at compilation stage. Please recompile adding it as asset or script.',
This led me to think that maybe I needed to run pkg package.json vs pkg app.js and manually define my assets instead of depending on auto-detection of path.join to resolve them for me.
so I include this following in my package.json:
"bin": "app.js",
"pkg": {
"assets": ["uploads/**/*"]
},
However, I still get the same issue. Any ideas on what else I should try or to get my /uploads directory included? Any help would be really appreciated.
I also got the same strange problem fey days ago. Finally got to manage it by using absolute path to include the assets.
I know that using the absolute path seem not to be the best solution. In my case I am using a complete copy of the solution in a specific folder before compiling it.
I'm not totally following. Can you provide some steps on what I would need to do to make this work. Assuming for your example that the directory we want to include is called uploads.
Lets say I have :
My pkg.json file wich hold configs for packaging:
Location:
{
"pkg": {
"assets": [
"../uploads/**/*",
"../../node_modules/**/*"
],
"scripts": [
]
}
}
Then in my package.json in scripts:
"pkgWin": "xcopy /e /s /I /Y ".*" "C:\Server-Output" && pkg C:/Server-Output/src/app.js -c C:/Server-Output/config/pkg/pkg.json"
As you can see, I called my pkg.json file from an absolute path from the copied folder of my server source. I dont know why but using a relative path here was not working. Very strange :s
Hope it works for you
I was having the same issue with assets not being included, but the suggestion from @isaelblais led me to the solution. I had this in my package.json:
{
"name": "demo",
"version": "1.0.0",
"pkg": {
"assets": "dist/client/**/*"
}
}
And running pkg like this:
pkg index.js --targets node10-win-x64
But the assets weren't being included. As it turns out, the package.json file doesn't seem to be used as a config file automatically. If I run pkg like this:
pkg index.js --targets node10-win-x64 --config package.json
Then the assets are included. 馃帀
I had the same problem when trying to package an app that allowed file uploads and then accessing those uploaded files. It appears to me that if you add a new file at runtime to a directory that is included in the asset paths, the pkg executable won't recognize the new file.
Ultimately I couldn't get it to work with pkg, but it worked like a charm when I built using nexe.
I had the same problem when trying to package an app that allowed file uploads and then accessing those uploaded files. It appears to me that if you add a new file at runtime to a directory that is included in the asset paths, the pkg executable won't recognize the new file.
Ultimately I couldn't get it to work with pkg, but it worked like a charm when I built using nexe.
Even faces the same problem and worked with nexe. But when I am using nexe with pm2 on centos, it did not work. pm2 seems to be working with pkg very fine on centos but not with nexe
-config package.json saved my day. Did not know that one has to specify that manually.
Most helpful comment
I was having the same issue with assets not being included, but the suggestion from @isaelblais led me to the solution. I had this in my
package.json:And running
pkglike this:But the assets weren't being included. As it turns out, the
package.jsonfile doesn't seem to be used as a config file automatically. If I runpkglike this:Then the assets are included. 馃帀