I have tried to run my node server multiple times I am getting this error, for this I tried to delete .next folder and build again after build complete it throws same error. It is running perfectly on my local machine.
`Could not find a valid build in the '${this.distDir}' directory! Try building your app with 'next build' before starting the server
Error: Could not find a valid build in the '/root/only4laughproject/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:435:23)
at new Server (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:44:29)
at module.exports (/root/only4laughproject/node_modules/next-server/index.js:4:10)
at module.exports (/root/only4laughproject/node_modules/next/dist/server/next.js:2:161)
at Object.<anonymous> (/root/only4laughproject/server.js:9:13)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
here is my package.json script
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "npm run-script build && cross-env NODE_ENV=production node server.js",
"go": "cross-env NODE_ENV=production node server.js"
}
on doing npm start command it is running next build command before project build finish it starts my server.js that's why this problem occur, I tried next build after build complete I hit node server.js. It resolve my issue.
Related
I get a MODULE_NOT_FOUND error after successfully installing the external module "file" with npm. It appears in the project folder with all its files as usual, the dependencies in the json file are also there. It happens with every npm package. I already reinstalled npm and tried different LTS versions of npm. I double checked the json file that the dependencies are corret.
This is the error message:
phila#DESKTOP-68STT9S MINGW64 /g/My Drive/Work - Software/WebDevelopmentCourse/Web Development/introNPMNODE
$ node test.js
node:internal/modules/cjs/loader:959
throw err;
^
Error: Cannot find module 'file'
Require stack:
- G:\My Drive\Work - Software\WebDevelopmentCourse\Web Development\introNPMNODE\test.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (G:\My Drive\Work - Software\WebDevelopmentCourse\Web Development\introNPMNODE\test.js:1:12)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'G:\\My Drive\\Work - Software\\WebDevelopmentCourse\\Web Development\\introNPMNODE\\test.js'
]
}
This is the json file:
{
"name": "intronpmnode",
"version": "1.0.0",
"description": "test",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "phil",
"license": "ISC",
"dependencies": {
"core-util-is": "^1.0.3",
"file": "^0.2.2"
}
}
the javascript "test.js" file:
var file = require("file");
make sure you are pointing the node command to a file that exists on your file system and There are no spaces between words, delete node_modules and package-lock.json, re-install dependencies and restart your IDE.
If the error is not resolved, try to delete your and (not) files, re-run and restart your IDE.node_modules package-lock.json package.json npm install
delete node_modules and package-lock.json
rm -rf node_modules
rm -f package-lock.json
clean npm cache
npm cache clean --force
npm install
I have tried to get the tensorflow.js library to work for days now.
I have installed on my computer
Python 2.7
Visual Studio 2019
Node 12.13.0
This is the steps I've done to produce the error:
Create empty folder
npm init inside the folder
npm install --save #tensorflow/tfjs-node
created a index.js file
added 1 line : require('#tensorflow/tfjs-node')
tried to run node index.js
got this error:
C:\Users\kim_1\Desktop\workplz>node index.js
internal/modules/cjs/loader.js:1003
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\C:\Users\kim_1\Desktop\workplz\node_modules\#tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1003:18)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\kim_1\Desktop\workplz\node_modules\#tensorflow\tfjs-
node\dist\index.js:44:16)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
my package.json
{
"name": "workplz",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"#tensorflow/tfjs-node": "^1.3.0"
}
}
It is related to the version of tfjs-node. Installing a specific version such as #tensorflow/tfjs-node#1.2.3 will fix the issue.
Uninstall the latest package
npm uninstall --save #tensorflow/tfjs-node
And install the version 1.2.3
npm install --save #tensorflow/tfjs-node#1.2.3
Update to the case:
#tensorflow/tfjs-node#1.3.0 has issues with Node version 12.13.0 (source https://github.com/tensorflow/tfjs/issues/2341)
Had to use #tensorflow/tfjs-node#1.2.11 with Node version 10.16.3
This might be the issue with Node and Tensorflow versions.
You can resolve it by upgrading the node version to 16.13 and #tensorflow/tfjs-node to 3.12.0.
Download Node 16.13
Upgrade #tensorflow/tfjs-node using the following command,
npm install #tensorflow/tfjs-node#3.12.0
Error: Cannot find module '../controllers/thermostatLogic'
Here is my dockerfile
FROM node:10-alpine
LABEL version="1.02"
RUN mkdir -p /app/node_modules && chown -R node:node /app
USER node
WORKDIR /app
COPY . /app
RUN npm install
RUN npm audit fix
RUN ls
RUN cd ./controllers && ls
RUN mkdir uploads &&\
cd uploads &&\
touch uploadedFile.csv
RUN cd ..
RUN ls
CMD npm start
EXPOSE 1000
I run the docker build -t hvacdoctor . command and then.
When it runs the ls command it returns:
---> Running in a6d2b49092ef
INSIDE
app.js
bin
controllers
env.js
exampleDevices.json
node_modules
package-lock.json
package.json
public
readme.md
routes
schema
test
views
yarn.lock
Removing intermediate container a6d2b49092ef
docker run hvacdoctordocke:latest
Error: Cannot find module '../controllers/t***Logic'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/node/app/controllers/fileLogic.js:8:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/node/app/routes/index.js:4:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
This all works with npm install & npm start without an error OUT of docker but why is this an issue within it?
I've tried a few different methods (git clone is out though because i need SSO for that etc)
These are the install instructions
1) download bash / node
2) create a folder called uploads and a file called uploadedFile.csv -make sure the file is in the folder.
3) npm install
4) npm start
Edit - here is a screenshot of the current folder structure.
Thoughts?
Edit - it was suggested I run the program with the following docker-compose.yml
node-app:
container_name: node-app
image: node:latest
restart: always
volumes:
- ./:/home/node/app
working_dir: /home/node/app
ports:
- 4000:4000
networks:
- main-network
command: "tail -f /dev/null && npm start"
Changed package.json
"main": "index.js",
"scripts": {
"preinstall": "npm i nodemon -g",
"start": "nodemon index.js",
}
^^ WITH this suggested start script nodemon starts index.js recursively - if I remove nodemon from the command it cannot find index.js. - I will likely edit this as it is in the routes folder to start as routes/index.js
ALSO to add clarity - previously I did not work with nodemon - I was running NPM start to start my project if that makes a difference (i.e I can git clone and run npm install && npm start and it will work.
Try the below docker configuration for a node application. It will work for you.
node-app:
container_name: node-app
image: node:latest
restart: always
volumes:
- ./:/home/node/app
working_dir: /home/node/app
ports:
- 4000:4000
networks:
- main-network
command: "tail -f /dev/null && npm start"
Here below is package.json
"main": "index.js",
"scripts": {
"preinstall": "npm i nodemon -g",
"start": "nodemon index.js",
}
Turned out it could not find it as my mac is not type sensitive but ubuntu is. Standardizing my file names fixed it.
This dockerfile worked fine
FROM node:12.14.0-alpine
LABEL version="1.02"
#create working directories etc.
RUN mkdir -p /app
# Create a /App Directory to install the application in
WORKDIR /app
# Copy all files from the main project to the container
COPY . /app/
RUN npm install
# COPY package*.json ./app/
# RUN npm install
# Standard npm commands
## DELETE THE FOLLOWING WHEN DOCKER CONTAINER IS FIXED
RUN cd node_modules
# create an uploads directory , go into it and add a placeholder file to avoid bug.
RUN mkdir uploads
RUN touch uploads/uploadedFile.csv
#go back into root folder
# RUN cd ..
# RUN ls
# start project and expose port 3000 as localhost
CMD node ./bin/www
EXPOSE 3000
I've set up webpack for my webextension.
In the package.json, I have defined the following script:
"scripts": {
"start": "webpack --config webpack.config.js"
},
so webpack can be started with one of these two options:
npm run start
webpack --config webpack.config.js
But while the npm run start works fine, the direct call to webpack --config webpack.config.js fails.
Here is my code: https://github.com/lhk/webextensions-webpack-boilerplate
You can reproduce the problem with the following steps:
git clone https://github.com/lhk/webextensions-webpack-boilerplate
cd webextensions-webpack-boilerplate
npm install
tsc -p tsconfig.json
webpack --config webpack.config.js
The error message is:
clean-webpack-plugin: /home/lhk/.local/share/Trash/files/temp.2/webextensions-webpack-boilerplate/dist has been removed.
(node:21823) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
/usr/lib/node_modules/webpack/lib/Chunk.js:827
throw new Error(
^
Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
at Chunk.get (/usr/lib/node_modules/webpack/lib/Chunk.js:827:9)
at /home/lhk/.local/share/Trash/files/temp.2/webextensions-webpack-boilerplate/node_modules/extract-text-webpack-plugin/dist/index.js:176:48
at Array.forEach (<anonymous>)
at /home/lhk/.local/share/Trash/files/temp.2/webextensions-webpack-boilerplate/node_modules/extract-text-webpack-plugin/dist/index.js:171:18
at AsyncSeriesHook.eval [as callAsync] (eval at create (/usr/lib/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:7:1)
at AsyncSeriesHook.lazyCompileHook (/usr/lib/node_modules/webpack/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/usr/lib/node_modules/webpack/lib/Compilation.js:1215:27)
at hooks.make.callAsync.err (/usr/lib/node_modules/webpack/lib/Compiler.js:541:17)
at _err0 (eval at create (/usr/lib/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at _addModuleChain (/usr/lib/node_modules/webpack/lib/Compilation.js:1066:12)
at processModuleDependencies.err (/usr/lib/node_modules/webpack/lib/Compilation.js:982:9)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
System information:
node version is: v8.12.0
npm version is: 6.4.1
operating system is: ubuntu 18.04 (64bit)
I'm new in Electron and the problem that I have is when I try to create an executable file.
I've tried many exemples and always I have the same problem. The executable file is created but when I try run it, don't work.
Appears the following error in a windows dialog
[Window Title] Error
[Main Instruction] A JavaScript error occurred in the main process
[Content] Uncaught Exception: Error: Unable to find a valid app
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:121:9)
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:188:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (module.js:683:10)
at startup (bootstrap_node.js:196:16)
at bootstrap_node.js:622:3
[OK]
This is my package.json:
{
"name": "my-electron-app",
"version": "1.0.0",
"scripts": {
"start": "concurrently \"ng serve\" \"npm run electron\"",
"electron": "electron ./src/electron.dev",
"ng": "ng",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
...
}
How can I fixed this?
After studied a lot I found the solution, I don't know if it's the best way, but works.
When I was executing the build for my application, in my file "angular.json" had the property outputPath with this way: "outputPath": "dist/my-electron-app", but to generate my windows packge I needed only "dist".
In this way when I execute de command:
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
it will generate only the folder "app" over my "electron\resources\" with the correct files, before that it generated the folder "app/my-app"
Thanks