on ‎2022 Oct 28 9:02 AM
By default, the node_modules will not be included into the content during the mbt build process. Whether there are some setting to force the mta to include the node_modules? As our project need to change some files after do the normal npm install'.
One trick I can figure out is that: we rename the "node_modules" to another name, and in the "start" script we build a softlink.
Request clarification before answering.
Just try another way to resolve the issue, but it failed also.
1: First install the library via "npm i""
2: Change the "node_modules" to another name like "node_modules_content"
3: In the package.json, change the script to create a soft link from the node_modules_content to 'node_modules' like the following
"scripts": {
"start": "ln -s node_modules_content node_modules; node --inspect ./index.js"
},
4: Run the "mbt build" to build the mta. So now the node_modules_content will be included
I guess this way should work. But during the test, it will fail with the error
"Cannot find module".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the reason (just guess,need to check the steps provided by the nodejs-buildpacks): for the nodejs application, even the package.json don't include any dependency, it will create the node_modules. this node_modules will overwrite the original node_module.
I try another way, it still not work:
try {
if (!fs.existsSync("./node_modules")){
console.error(" !! node_modules not existed, rename it");
fs.renameSync("./node_modules_content", "./node_modules", "dir");
// in window, it runs fine. But in BTP, maybe it is not really sync
while (true) {
if (!fs.existsSync("./node_modules")) {
console.error(" node_modules not exist afer the symlinkSync");
} else {
console.error(" **** now node_modules exists,");
break;
}
}
tryStartExpress();
} else {
console.error(" ** node_modules existed");
tryStartExpress();
}
} catch (error) {
console.error("$$$ error happend:", error);
}
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.