Problem in running azure function offline - azure

When I have serverless.yml & webpack.config.js at the root level then the project works fine but if I move serverless.yml & webpack.config.js in some other folder like "apps" (purpose of moving is using nx, there will be multiple applications in the project so serverless.yml & web.config.js file should be unique for each application) then it breaks with error "poc/apps/adaptor-sms-msg91/node_modules/.bin/func ENOENT".
The reason of error is that it is looking for node_modules inside "adaptor-sms-msg91" folder but actually it is at root level i.e. inside "poc" folder
I think I am missing some basic property, if somebody can please point me in right direction.
Poc structure:
I am running "sls offine" command inside "poc/apps/adaptor-sms-msg91"
Note: If I run the application with same structure for aws cloud then it works perfectly fine.
Below thing also I tried in serveless.yml file, but no success:
custom:
webpack:
includeModules:
packagePath: '../../package.json'
nodeModulesRelativeDir: '../../'

Related

Debug issue in vscode with typescript, nodemon, and external projects

Thank you for anyone who is able to offer some insight about what is going on. VS Code debugging has always been finicky, but I've got a situation that I think should work and it isn't.
Issue:
I can set breakpoints in typescript and debug in 2 of my projects (server and common-internal), but not the 3rd (common-external). Why can't I debug common-external, and how do I set it up so I can? VS Code cannot find the source to bind the breakpoint.
I've created a simple repo to reproduce the issue I'm seeing:
https://github.com/snotmare/debug-issue
Steps to reproduce:
Clone repo
Run 3 init tasks (for common-internal, common-external, and server)
Run 2 watch tasks (for common-internal and common-external)
Run the start server task
Run the debugger by attaching to the process
Set a breakpoint in server/src/index.ts (works)
Set a breakpoint in common-internal/src/utils.ts (works)
Set a breakpoint in common-external/src/external-utils.ts (does not work)
Project setup:
Typescript project with a utils class (common-internal).
NodeJS server project that imports common-internal and common-external.
Both of these projects are within the same folder, with a .vscode folder at the same root for task and launch config.
External project setup:
Typescript project with utils class (common-external).
This is setup exactly the same as common-internal, just renamed.
This has its own .vscode folder for task config.
The server project depends on the 2 common projects like this:
"dependencies": {
"common-internal": "file:../common-internal",
"common-external": "file:../../common-external/common-external",
"express": "4.18.2"
},
I believe the issue is related to the folder structure, which looks like this:
root folder
- test-app
- - .vscode
- - common-internal
- - server
- common-external
- - .vscode
- - common-external
The folder structure needs to be this way because I want test-app to be in a git repo while common-external is in a separate git repo.
When I debug the server, why can't I set a breakpoint in common-external and debug it? Thank you for your help!
Github issue for vscode:
https://github.com/microsoft/vscode/issues/169033
Ben
I found the solution for this by accident. I was able to update the outFiles for my launch.json file to look for files outside of the workspace folder...
"outFiles": [
"${workspaceFolder}/**/*.js",
"${workspaceFolder}/../common-external/**/*.js",
"!**/node_modules/**"
]
The vs code debugger is still finicky when it comes to my real (larger) project. Sometimes it finds the source files, sometimes it doesn't. Has anyone else experienced performance issues with the debugger?

How to resolve path to a file within node_modules

Problem loading a file using relative path when my node app is initialised using a another node app
I have created an npm which relies on a file stored relative to project root. something like this
index.js
- res
- config.json
Now I read the config.json using following code
const pathToConfig = path.resolve(__dirname, '../res/config.json')
This works great locally.
But in my prod setup this app is initialised by another node app.
And __dirname resolves to root of that app so all my logic to find config.json get messed up.
Is there any way I can read the file without worrying about how node app was initialised?
Have you tried the command process.cwd()? It is almost the same as __dirname but does differ slightly.

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 (e.g. 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 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!

app.yaml in different directory than main.js?

I have a Node.JS application that I want to deploy on AppEngine. At the moment I am getting following error:
Beginning deployment of service [default]...
Building and pushing image for service [default]
ERROR: node.js checker: Neither "start" in the "scripts" section of "package.json" nor the "server.js" file were found.
ERROR: (gcloud.app.deploy) Your application does not satisfy all of the requirements for a runtime of type [nodejs]. Please correct the errors and try again.
This makes sense as this is the folder structure:
client
server
main.js
app.yaml
As you can see I have a separate folder for my client code and server code.
If I put the app.yaml file inside the server folder, the deployment works but when I try to access the app it cannot find the client files as they were not part of the deployment.
Is there anyway to configure this in the app.yaml or do I need to refactor my app?
actually app engine required package.json in your root directory ... and in which put script of start.. like start:node server/main.js

Unexpected token import - using react and node

I'm getting an error when running my react app: Uncaught SyntaxError: Unexpected token import
I know that there are a plethora of similar issues on here, but I think mine is a little different. First of all, here is the repository, since I'm not sure where exactly the error is: repo
I'm using create-react-app, and in a seperate backend directory I'm using babel (with a .babelrc file containing the preset es2015). The app worked fine until I added another file in a new directory in the backend folder (/backend/shared/validations/signup.js).
I was using es6 before that too, and it was working perfectly fine. First I thought it was some problem with windows, but I cloned the repo on my Ubuntu laptop and I'm getting the same error there.
Some things I tried already:
Move the entire folder from /backend to the root folder
Move just the file (signup.js) just about everywhere
So no matter where the file is, the error stays the same. If I remove the entire file and all references to it the app works again.
I think this error is pretty weird, considering I'm using es6 everywhere else in the app without trouble. It would be great if anyone could help me with this error.
edit: If you want to test this on your own machine just clone the repo and run npm start in the root folder (and also npm start in the backend folder, but that isn't required for the app to run, or for the error to show up).
That's what's happening:
Your webpack is set to run babel loader only in the src folder (include directive).
To change that, one approach is:
1) extract webpack configuration with npm run eject (don't know if there is another way to override settings in react-create-app). From the docs:
Running npm run eject copies all the configuration files and the
transitive dependencies (Webpack, Babel, ESLint, etc) right into your
project so you have full control over them.
2) in config/paths.js, add an appShared key, like that:
module.exports = {
/* ... */
appSrc: resolveApp('src'),
appShared: resolveApp('backend/shared'),
/* ... */
};
3) in config/webpack.config.dev.js, add the path to the babel loader, like that:
{
test: /\.(js|jsx)$/,
include: [ paths.appSrc, paths.appShared ],
loader: 'babel',
/* ... */
},
It works now!

Resources