简体   繁体   中英

NodeJS/CloudFoundry - failed: The app upload is invalid: Symlink(s) point outside of root folder

I'm testing CloudFoundry on IBM and are running NodeJS.

When trying to cf push my application I get the following error:

failed: The app upload is invalid: Symlink(s) point outside of root folder

In my appllcation I have the following code:

return res.sendFile(path.join(__dirname +'/tvshows/'+ guide +'.html'));

When not using path.join and simply use:

return res.sendFile(path.join('./tvshows/'+ guide +'.html'));

I get this error instead:

TypeError: path must be absolute or specify root to res.sendFile

What to do?

I've also tried stuff like path.join((process.env.BUILD_DIR || __dirname), and return res.sendFile('index.html', { root: path.join(__dirname, 'tvshows', guide) }); but no luck.

The fail came from my node_modules folder. Adding .cfignore with node_modules/ fixed the issue.

You didn't mention the version of the cf cli that you're using, but I think that this is expected behavior starting with version 6.34.0.

push now preserves relative symlinks in app files. This makes it easier to work with Node.js apps using npm link, but note that it now errors when it detects a symlink pointing outside the app folder (eg a node_modules folder containing external symlinks).

https://github.com/cloudfoundry/cli/releases/tag/v6.34.0

I think you're running into the second part, "how errors when it detects a symlink pointing outside the app folder". It's nothing to do with the code in your app, but rather somewhere in your project folder there is a symlink which references another file that is not under the root of your project.

If you're on a unix-like system you can run find . -type l find . -type l to find all the symlinks under the current directory. Then you just need to figure out which one is pointing outside of the project root.

Options are to remove that symlink, point it to something under your project root or use .cfignore to ignore that file (which is what you ended up doing).

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM