How to deploy Nuxt.js to Elastic Beanstalk? - node.js

I am very new to AWS and i have been following the tutorials out there but couldn't find the answer. So, what i did was i created simple nuxt application, no changes to the framework's script or anything. I set my elastic beanstalk to run node.js settings. and then i tried to deploy my /dist folder(using nuxt build) with the application's json folder as told by every tutorials. but it gives me this this is what it looks on my webpage
I think i have something wrong with which folders i deploy or do i have to actually deploy via the aws CLI, would that make a difference at all?
eb log :
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2019-09-29T16_00_28_939Z-debug.log
> portfolio#1.0.0 start /var/app/current
> cross-env NODE_ENV=production node server/index.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/var/app/current/server/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

The nodejs logs indicate to me that there is an issue with the build, an issue with how it's zipped, or an issue with your start command.
The most common is incorrectly zipping source files
When you create a ZIP file in Mac OS X Finder or Windows Explorer, make sure you zip the files and subfolders themselves, rather than zipping the parent folder.
In other words, do not right click the dist folder and click "zip", select all the files and folders (including hidden ones) and zip those. Elastic beanstalk, and many other AWS services, expect the zip to unpack into a flat structure, and not contain the parent folder when unzipped.
If this does not solve your problem, make sure you're zipping the correct folder. Try deleting your .nuxt and /dist folders, and running npm run build locally. The folder that is produced (defaults to .nuxt) is the folder whose contents need to be zipped.

The reason it is throwing that error is because your launch command starts with cross-env. When it sees that it tries to run the globally installed package cross-env but it is not available globally, so it throws that error. There are a few possible ways to address this:
The easiest is to just change the start command to use a relative path to the locally installed version of cross-env, so your command should look something like this:
node_modules/cross-env/src/bin/cross-env.js node server/index.js
You might also try adding npx to the front of your command, like so:
npx cross-env NODE_ENV=production node server/index.js
This should work but I have found that sometimes I get errors with specific packages, from what I can tell it is a bug with npx but I haven't had time to look into it. Notably I did see this bug with a nuxt js app specifically so you might too, however I was using the nuxt cli which you are not.
The third option is you could look into installing the package globally using ebextensions. In my work I haven't come across a situation where that has been necessary.

Related

Node.js node:internal/modules/cjs/loader:936 error while trying to use discord.js

I'm trying to make a discord bot with the command prefix "*" but when I try to get the bot online/run it, it gives me this error:
node:internal/modules/cjs/loader:936
node:internal/modules/cjs/loader:936 throw err; ^
Error: Cannot find module 'C:\Users\name\const'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }
The module I'm using is discord.js and i've installed discord.js on CMD and the VSC terminal but it still comes up with the MODULE NOT FOUND error. I've looked around the internet and I can't find one that fixes the problem. I've tried reinstalling Node.js but it won't stop coming back. Please help, Thanks!
same error with me but I just change file dir cause I run node <filename.js> in the wrong dir so I just change like ---
the first step chacks you are in the right dir or not type: > ls
then if you are in the right dir then type: node <filename.js> if not then change your dir to change dir type: cd <filename>
and then run your first app or file for run type: node <filename.js>
I hope your error is solved!
you need to run it as an administrator so sudo(whatever you tryna run) as long as you are in the right directory
On Windows I solved it like this.
I went to the folder: C:\Users\Documents\AppData\Roaming\npm
And I deleted the file. create-react-app.
I started the project again, and it worked.
root cause, my path was messed up, but I only figured that out once I found where my npm packages where. I had thought they were in ../Programs/Roaming/npm etc but since an update (I think to node) my packages were actually in a Python Lib subdir.
Your Answer might be the same as mine, and I found out all this by using the
npm list -g
Command - which showed the globally installed packages, but also highlighted that this was nowhere to be found in my path
Hope this helps someone!
I had the same error and it was a case of trying to run the file in node from the wrong location.
My solution was to use the terminal and CD into the exact folder the file I was trying to run were and then after that I could run node filename.js.
In my case (this error ocurred at running docker container of next app), it was because I was running docker-compose without the flag --build, but of without copy lock files (package-lock.json and/or yarn.lock).
I updated my Dockerfile:
[...]
COPY yarn.lock .
RUN yarn install --frozen-lockfile
CMD [ "yarn", "dev" ]
And after, run with docker-compose up --build
When I was following a JS tutorial i got this error message too.
The problem was I copied an existing JS file and renamed it but it
through that error when i ran it.
When i created a new JS file, and copied the code in, and ran, it worked.
Before starting your server you need to make sure that the start file is mentioned below
cross-env NODE_ENV=production node index<start file name eg:index for index.js>
It happens when you run npm run start without getting into the project first... So, before starting to compile your project, run this command: cd <project folder name>...
It will stop showing the "Missing Module" Error and smoothly run your desired output in your browser
When was trying to find 'npm' & 'Rdme' path from command prompt to update the Rdme was getting this error Log
This error is caused when file can't be found or its a wrong path, In my case I added the missing file to respective folders- configured & updated in Environment variables (after adding missing files)
For the coming next. For me I'v got the error when I tried to run a package.json script with the npx run rather npm run.
In my case, I used chocolatey to install nodejs and it fixed my issue.
Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following command:
choco install -y nodejs-lts
I hope it works for you too :)
The error tells that you've required packages that you haven't installed. So please make sure that you've installed every package that you've required in your bot. Also if you're sure that you've installed it, please check it again, there were namely some problems for some people that some of their packages got uninstalled while updating Discord.js to version 13.
For your problem in the comments ("TypeError [CLIENT_MISSING_INTENTS]"), it is now required in Discord.js version 13 to add your needed intents in the client. Please read this part of the Discord.js guide.
I fixed this issue by changing the opened directory of the terminal. Just go to the terminal and type: cd <folder name> until you reach the folder in which your js file is located. Then save and run again.
npm uninstall webpack-cli -D
npm install webpack-cli#3.3.12 --save-dev
than work fine

Can I use a custom node_modules path with create-react-app

I'm working on a project inside a VM (really docker on windows via vscode remote-containers). I would like to avoid building my react app at $(pwd)/node_modules, because everything under $(pwd) is synced to my windows file system which causes serious performance issues.
I'm fairly new to nodejs in general, but I'm surprised how difficult this seems to figure out.
I successfully started with this:
yarn --modules-folder /tmp/vendor
This gave me a /tmp/vendor folder with expected dependencies listed.
For the next step, I want to run the development server, so I run this:
yarn --modules-folder /tmp/vendor start
I get /bin/sh: react-scripts: command not found. I figure yarns --modules-folder doesn't reconfigure PATH information when running commands (yarn start calls react-scripts start). So I just added my own PATH as a workaround:
PATH=$PATH:/tmp/vendor/.bin/ yarn --modules-folder /tmp/vendor start
But now I get this:
[root#352b76226b83 owio]# PATH=$PATH:/tmp/vendor/.bin/ yarn --modules-folder /tmp/vendor start
yarn run v1.22.5
$ react-scripts start
internal/modules/cjs/loader.js:965
throw err;
^
Error: Cannot find module 'react-dev-utils/crossSpawn'
Require stack:
- /tmp/vendor/react-scripts/bin/react-scripts.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:962:15)
at Function.Module._load (internal/modules/cjs/loader.js:838:27)
at Module.require (internal/modules/cjs/loader.js:1022:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/tmp/vendor/react-scripts/bin/react-scripts.js:18:15)
at Module._compile (internal/modules/cjs/loader.js:1118:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)
at Module.load (internal/modules/cjs/loader.js:982:32)
at Function.Module._load (internal/modules/cjs/loader.js:875:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/tmp/vendor/react-scripts/bin/react-scripts.js' ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command
Since it is complaining about missing modules, I also set the NODE_PATH (I guess yarn doesn't forward this variable either):
NODE_PATH=/tmp/vendor PATH=$PATH:/tmp/vendor/.bin/ yarn --modules-folder /tmp/vendor start
With this, I get:
./src/index.jsx
Line 0: Parsing error: Cannot find module 'eslint-scope' from '/tmp/vendor/eslint/lib/api.js'
I'm stuck here, because eslint-scope does exist, and I've already what I can to work around path problems.
I'm half tempted to start trying other tools outside of CRA and yarn but I don't really know the ecosystem well enough yet to understand how to port my application over. Any advice would be greatly appreciated.
EDIT:
I've gotten closer by changing vendor to node_modules. I guess this convention is somehow necessary. I also added NODE_PATH=/tmp/node_modules to a .env file, and the --modules-folder /tmp/node_modules to a .yarnrc file.
EDIT 2:
I made a symlink for $(pwd)/node_modules -> /tmp/node_modules as suggested and this seems to have worked this time around, given that I added the NODE_PATH to .env.
It seems all the react-script stuff is working now, but when compiling the local source files under src/components/, I get errors about not resolving modules from /tmp/node_modules that do indeed exist.
After some tinkering and support from Estus, I found that having the following things works for me:
.env file with NODE_PATH=/tmp/node_modules
.yarnrc file with --modules-folder /tmp/node_modules
symlink for $(pwd)/node_modules -> /tmp/node_modules
I'm not sure why the symlink is necessary, and would love to know if anyone has a .env like solution. It seems my local source files are compiled against this folder regardless of having NODE_PATH set.
Other oddities I don't understand, but maybe someone will:
I could not just have NODE_PATH as a variable in my yarn command. It seems having the value in .env changed how modules within node_modules were compiled.
I could not use a name other than node_modules. No idea why.
As an aside:
For anyone landing here having the same issue (slow docker performance on windows or mac), you may need to make sure you're editor is not indexing node_modules. For example, I have set files.watcherExclude in my .vscode/settings.json to include "**/node_modules": true,".

ElasticBeanstalk nodejs.log can't find module 'hogan.js'

I have a simple node.js app that is using "hogan": "^1.0.2" (from packages.json under "dependencies").
It has been failing to deploy, and looking in the logs, I am seeing (multiple times):
Error: Cannot find module 'hogan.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
I'm fairly new to node.js on EB, and have just been following http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html with a pre-existing Express app.
Assuming EB runs npm install for me (is that a safe assumption?), what might the issue be?
I was using "hogan": "^1.0.2" instead of "hogan.js": "^3.0.2", which worked locally but not on EB.
hogan is just an unofficial alias someone made to hogan.js.
I do not get hogan.js errors any more after making the switch.
For what it's worth, I also had an issue similar to this and determined that it was due to file case issues. In the node EB container, the OS is case-sensitive, and because I was ignoring file case changes in git, it didn't update the file casing in the repository.
You should run git config core.ignorecase false if this is the issue.
You might also change "hogan": "^3.0.2" to "hogan": "*" because EB does run npm install for you. If EB can't find the specific version with "^", it might not install the package as you did locally. Also you might check your file structure before you do eb create or eb deploy. You might include something unnecessary if you are using the command line. I suggest that you create an application.zip file with files you need, such as package.json, app.js and index.html and upload it through GUI. Don't ever pack up node_modules in your .zip file, that's troublesome.

why babel stores .babel.json in USERPROFILE path

I'm running a nodejs app on azure web apps and i'm trying to integrate babel using npm in it. The problem is that babel is trying to acccess a file at
%USERPROFILE%
named .babel.json, a file that doesn't exist. This is most likely installed by:
npm install -g babel
On azure web apps, i can't seem to find it at all (even after running npm install -g babel in kudu for the site).
I copied the file in %USERPROFILE% myself to %USERPROFILE% using kudu but on web app restart the file disappears.
Is there a way to make babel work on web apps?
UPDATE
I did omit some things. The error appeared when i tried load babel/register.
require('babel/register')({
optional: ["es7.asyncFunctions"]
});
and the actual error i see in the streaming logs is
Application has thrown an uncaught exception and is terminated: Error:
ENOENT, no such file or directory 'D:\local\UserProfile.babel.json'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.writeFileSync (fs.js:977:15)
at save (D:\home\site\wwwroot\node_modules\babel\node_modules\babel-core\lib\api\register\cache.js:35:19)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
the project is on Github
I had this same problem, solved it by disabling the babel cache by setting the environment variable BABEL_DISABLE_CACHE=1 in my Application settings.
You can read more about the babel cache here:
https://babeljs.io/docs/usage/require/#environment-variables
You change the store location of .babel.json by BABEL_CACHE_PATH
I think its better than disable caching
BABEL_CACHE_PATH=any_writable_and_exist_dir/babel.cache.json
The error appeared when i tried load babel/register.
Please check the Cache.js at (..\node_modules\babel\node_modules\babel-core\lib\api\register\Cache.js) to see if there is any babel cache path definition, e.g.
process.env.BABEL_CACHE_PATH || _path2["default"].join(_homeOrTmp2["default"], ".babel.json");
If you leverage this kind of variables, it's needed to have BABEL_CACHE_PATH app setting key and value of ./cache otherwise anything with babel wouldn't work on azure. Please refer to http://blog.syntaxc4.net/post/2012/07/26/accessing-app-settings-configured-in-microsoft-azure-web-sites-using-php-and-node-js.aspx in case you wanna know the details of accessing app settings in Azure web site using node.js.
Should you have any further concern, please feel free to let us know.
I create a nodejs app from Azure Gallery "Node JS Empty Web app" and run the command npm install -g babel in Kudu. I tried to reproduct your issue, but failed that the babel is not trying to access the file .babel.json at %USERPROFILE%.
On Azure, the npm global modules will be installed into the path "D:\local\AppData". When you restart the WebApp, the node global modules will be deleted.
If you have to use the node global modules, you can configure a startup task for a node web role to install node modules when web role start up in Cloud Service. Please refer to https://azure.microsoft.com/en-us/documentation/articles/cloud-services-startup-tasks/.
Normally, installed node modules by using npm install <module-name> at the path "wwwroot" of Kudu Debug Console on Azure Web Apps.
I tried to install the babel module at the path "wwwroot" and run the command node_module\.bin\babel, and write a file include the code require('babel') to run it successfully. It works fine.
Best Regards.

nodejs module.js:340 error: cannot find module

I installed nodejs in C:\Program Files (x86)\nodejs
then I created a .js file and saved it in my desktop just to output 'hello world' in the console:
console.log('hello world');
When I tried to run the file from the command prompt:
C:\Users\Laura>cd desktop
C:\Users\Laura\Desktop>node nodeTest.js
I get:
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\Laura\Desktop\testNode.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I read many other related questions, and some of them recommend to run the install, and so I did.
C:\Users\Laura>npm install -g express
But no luck, still getting the same error message.
EDIT: This answer is outdated. With things like Yarn and NPM 5's lockfiles it is now easier to ensure you're dependencies are correct on platforms like Heroku
I had a similar issue related to node_modules being modified somehow locally but the change was not reflect on Heroku, causing my app to crash. It's relatively easy fix if this is your issue:
# Remove node_modules
rm -fr node_modules
# Reinstall packages
npm i
# Commit changes
git add node_modules
git commit -m 'Fix node_modules dependencies.'
git push heroku master
Hope that helps for others with a similar issue.
I was having the same problem with a server someone had written a while back. It turns out I didn't have a few things installed that the script required.
This question was helpful to me.
I ended up being able to use:
npm install yourMissingDependency
Although in your instance it may just be a file that it doesn't have a path to.
You could try putting that file in the same folder you are running the node script from.
I think the issue is the NODE_PATH environment variable. I had the same problem but once I issued (on Windows)
set NODE_PATH=C:\Users\MyUser\node_modules
then all worked ok.
Cheers,
Restart your command prompt and check your path variable (type: path).
If you can't find find nodejs installation dir from output add it to the path variable and remember to restart cdm again...
I had a nearly identical issue, turned out my JS file wasn't actually in the folder I was calling it from, and I had gone one folder too deep.
I went up one directory, ran the file, it recognized it, happily ever after.
Alternatively, if you go one folder up, and it gives you the same error, but about a different module, take that same file in your parent folder and move it into the subfolder you were previously trying to run things from.
TL;DR- your file or its module(s) is not in the folder you think it is. Go up one level
Try typing this into the Node command-line environment:
.load c:/users/laura/desktop/nodeTest.js.
It should work for what you're trying to do.
If you want to call the file directly, you'd have to have it in the root directory where your Node installation resides.
Hi fellow Phonegap/Cordova/Ionic developers,
I solved this issue by doing the following
1. C: drive -> Users -> "username" eg. john -> AppData -> Roaming
2. Inside the "Roaming" folder you need to delete both "npm" and "npm-cache"
folder.
3. Now build your project, and it should work
Happy coding!!!
I faced the same problem. I just copied the testNode.js file(that contain the test code) and pasted into the root of nodejs directory manually. I tried this command C:\Program Files (x86)\nodejs>node testnode.js
Bingo! I received this message.
Then I typed this url in a browser and received the message "Hello World".
Hope this help somebody.
You need to:
Remove the tick of Hide extensions for known file types from Windows Explorer folders option
Your file will appear as testNode.js.txt
Remove the trailing .txt so as the file to be resolved as JS file
That's it, now it works!
I had the same problem then I found that I wasn´t hitting the node server command in the proper directory where the server.js is located.
Hope this helps.
Try npm install --production and then npm start.
Easy way for this problem
npm link e
I also got this issue and this was due to wrong path that we mention while running. Check your file path and also make sure that there is no space between the name of your directory name.
Try npm start in Node.js Command Prompt.
Look at the end of the messages - it gives you the path of log file in "Additional Logging Details ..." something like c:\users\MyUser\npm-debug.log
Open this file in Notepad and find the real address of Node.exe :
something like C:\\Program Files\\nodejs\\\\node.exe
Try cd to this path
Call node.exe + <full path to your server file.js>
Server is listening on port 1337 !
I had the same problem, but finally I tried copying the Node_modules folder in the same project folder, and it worked.
I executed following command and it works for me.
PM> npm install ee-first ee-first#1.1.0 node_modules\ee-first
While i tried to run my first node application i had encountered the same issue but when i tried to see what the issue might be it was the path of the file. I was running the node .js from different location and hence encountered the issue. When i fixed the path this worked fine.
In my case, i got this error because i was just in the wrong directory. So node couldnt find the module that i wanted to run. Just be sure your node file is in your Desktop directory.
If you are using a framework like express, you need to put the package.json file into the folder you are using and don't forget change main name.
Remove the fs extra from the path -
path: 'D:\\FrontEnd Dev\\Git projects\\Appname-master\\node_modules\\webpack-manifest-plugin\\node_modules\\fs-extra\\package.json',
requestPath: 'fs-extra'
And run the command npm i
Make sure you saved the file as JavaScript. Un check 'Hide extensions for all known type' check box in Folder Options window will show you the correct file extension(Folder>>view>>Option).
Faced the same problem while trying to run node-red.
node <directory structure where js is located>/red. js
In my case it was :
node AppData/Roaming/npm/node_modules/node-red/red.js

Resources