Cannot find module '/app/dist/bin/www.js' - node.js

So I am having this error on Heroku. I just woke up this morning and found it after adding a new feature. It says my www.js file is not found. This file is not on GitHub. I am writing typescript so I'm guessing Heroku will build my project and create a "./dist" folder which will include the /bin/www.js file. The application was working before and still works locally. The application still builds successfully. I have tried adding a Procfile and also used a preinstall script but nothing seems to work. Is it possible to know if the "./dist" folder was successfully created?
Error on Heroku:
Folder Structure:
Scripts:
"scripts": {
"test": "SET NODE_ENV=test&& mocha --exit -r ts-node/register tests/**/*.ts",
"dev": "nodemon src/bin/www.ts",
"start": "nodemon dist/bin/www.js",
"build": "tsc -p .",
"lint": "eslint . --ext .ts",
"precommit": "npm run lint&& npm test",
"preinstall": "npm run build"
}`
The Procfile just has: web: npm start

I found the problem. Apparently, the new build created another www.js file in "dist/src/bin/www.js" and deleted "dist/bin/www.js" on Heroku. I have no idea why this happened. So I changed my start script to "nodemon dist/src/bin/www.js".

Related

NPM project.json script section tasks are not executing correctly

This is part of my project.json
"scripts": {
"prestart": "babel-node buildScripts/startMsg.js",
"start": "npm-run-all --parallel security-check open:src lint:watch",
"open:src": "babel-node buildScripts/srcServer.js",
"lint": "esw webpack.config.* src buildScripts --color",
"lint:watch": "npm run lint -- --watch",
"security-check": "nsp check",
"localtunnel": "lt --port 3000",
"share": "npm-run-all --parallel open:src localtunnel"
}
When I run my tasks manually like:
"nsp check" or "npm run lint -- --watch"
it works fine I see output in the console.
Problem is when I'm running my whole app "npm start" or "npm run lint:watch" these tasks are seems not running although I'm not getting any errors in the console and app seems to run fine I'm getting expected content.
What could be the problem here? and what is the difference if run nsp check or npm run security-check shouldn't the same thing happened?
Example when what shows my console when I execute these two above:
console output

Getting error no such file or directory in node js

I am new here in node js, so i am sorry for this issue, I need to rebuild and run webpack, for that i have 2 commands here is that
"scripts": {
"build": "NODE_ENV=production ./node_modules/webpack/bin/webpack.js --optimize-minimize",
"start": "NODE_ENV=development ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --hot-inline"
},
Where i run this NODE_ENV=production ./node_modules/webpack/bin/webpack.js --optimize-minimize command it says file or directory not found can anyone please help me how can i get rid of that ?

Deploying simple nodejs app to Heroku - Procfile not working

I'm trying to deploy my Express server to my Heroku app, but every time I do, I get an error and it crashes.
I setup my Procfile with the following code: web: node /src/server.js
Where server.js is not in the root of the directory. However, when I try to start the server, I get an error in the logs: Error: Cannot find module '/src/server.js'
When I run the app locally, I have to run npm start in order for it to run the server correctly. Here is the relevant "scripts" portion of my package.json file:
"scripts": {
"start": "NODE_ENV=dev nodemon ./src/server.js --exec babel-node",
"prebuild": "rimraf dist",
"build": "babel ./src -d dist --presets es2015,stage-2 --ignore spec.js,node_modules",
"serve": "NODE_ENV=production node dist/server.js",
"start_babel": "babel-node ./server.js --preset=babel-preset-es2015",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ."
}
Since the Procfile overrides the package.json script commands, why is it having trouble finding my file when I've explicitly set it?
I'm not sure about the leading slash. Does using ./src/server.js help at all?

File on heroku not found

I have a single-page application which is written in NodeJS and deploy on Heroku.
I define my Procfile like:
web: PORT=$PORT webpack -p --config ./config/webpack/serverProd.js --progress && node ./dist/server.js
The reason why I do not use heroku-postbuild deploy hook is because I can not get the PORT variable which is assigned by Heroku dynamically, and this is the only way I can access PORT variable.
But when I run heroku run bash and search around in the container of Heroku...
ta da!
I can not found my server.js which it should be exist in the /app/dist/ directory.
I am pretty sure there is something I misunderstand. Can anyone point that out?
Really appreicate!
This is how I setup my nodejs\npm project on heroku
Procfile
web: npm run build && node dist/index.js
package.json
"scripts": {
"clean": "rm -rf dist && mkdir dist",
"serve": "node dist/index.js",
"start": "nodemon --inspect src/index.js --exec babel-node",
"build": "npm run clean && npm run build-server",
"build-server": "babel src -d dist",
"test": "mocha --compilers js:babel-register"
},
Try to start the app from dist/server.js instead of ./dist/server.js

npm: how to run test & lint on each change?

I am using a bare npm ( no grunt/gulp) approach to develop my new MEAN project.
My config is like the following:
File package.json:
...
"start": "nodemon ./bin/www",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"dependencies": {
...
},
"devDependencies": {
...
},
Before starting, I run an npm start and nodemon starts monitoring my project tree for changes, triggering a restart after each source file change.
So far so good.
But what if I'd like to include - say - the lint and/or the test stages on each restart?
I didn't find any clue nor in the nodemon page nor in the npm one...
So you should have a definition of the start in your package.json to first run lint, then test then the actual run server.
You can find an example in following post:
http://substack.net/task_automation_with_npm_run
you should run the 'npm run monitor' command to start the monitoring and the restart should call the npm run start script.
but basically you want to have (based on your package.json)
"scripts": {
"start": "npm run lint & npm run test & node ./myfile.js",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"monitor": "nodemon ./bin/www"
.....

Resources