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.
Related
I have a project that is using svelte-kit and Tailwind CSS. I recently moved it over to using docker compose. When I run my containers, I run them in WSL because they usually run better there. When I start the container that runs the development server, it starts up and runs just fine, but when I open the URL in my browser, I get the following error.
Error: EACCES: permission denied, mkdir '/root/.tailwindcss/touch'
at Object.mkdirSync (node:fs:1325:3)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/lib/setupContext.js:44:8)
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 Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/index.js:7:22)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
I'm unsure what's causing this error but I think it has something to do with tailwind.
Here is a link to my docker-compose file: https://github.com/DriedSponge/GorillianCurrencyConversion/blob/master/docker-compose.yml
If you want to try it out yourself, here is a link to the repo and the steps to reproduce:
https://github.com/DriedSponge/GorillianCurrencyConversion
Install Packages: docker-compose run npm install
Start Dev Server: docker-compose --profile dev up -d --build
Please let me know if you have any ideas on what's happening, or if you need any additional information from me. Thanks in advance!
It looks like Tailwind is trying to create a touch file which has something to do with watching for file changes during development, specifically when Tailwind is in JIT mode.
You might be able to fix this by either:
Allowing write access to /root/.tailwindcss.
Disabling touch by setting the TAILWIND_DISABLE_TOUCH environment variable.
Changing the touch file directory by setting the TAILWIND_TOUCH_DIR environment variable to a location where writing is allowed.
To set environment variables, it might be most convenient to set those in your package.json file. Simply add the environment variable in front of the relevant command under scripts, such as:
"dev": "TAILWIND_TOUCH_DIR='/var/www/html/.tailwindcss/touch' svelte-kit dev"
Be careful not to point this directory to one containing important files, since Tailwind will delete all the files inside that directory.
None of these options are documented anywhere except for comments in the source so I'm not entirely sure what the consequences of this are, especially during development mode. I believe that this is used for communicating when files have changed, so option 1 or 3 might be the safest choices.
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.
I am working with aws lambda using serverless framework, I changed the runtime from nodejs8.10 to nodejs10.x, then I got an errortrace,
{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'jmespath'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'jmespath'"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"," at Object.<anonymous> (/var/runtime/index.js:36:30)"," at Module._compile (internal/modules/cjs/loader.js:701:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)"," at Module.load (internal/modules/cjs/loader.js:600:32)"," at tryModuleLoad (internal/modules/cjs/loader.js:539:12)"," at Function.Module._load (internal/modules/cjs/loader.js:531:3)"," at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)"," at startup (internal/bootstrap/node.js:283:19)"]}
What is the cause of this issue and how can get it fixed?
I hit the same problem Error: Cannot find module 'jmespath' and solved it.
Do you use aws-sdk via node_modules? like follows
var aws = require('aws-sdk');
If so you just remove aws-sdk from node_modules.
remove aws-sdk for yarn
yarn remove aws-sdk
remove aws-sdk for npm
npm uninstall aws-sdk
aws-sdk has been included to lambda since nodejs10.
see: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
Try to put ./ in front of your module name. I changed my name from require("xxx") to require("./xxx") and it worked again. In my case, the local module file i wanted to add (xxx.js) is on the same level as the index.js file.
I'd also like to add that as a preliminary step before adjusting your path, check and verify your dependencies listed in your package.json(s) files.
I've seen this error "Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'something' occur in the aws cloudwatch logs.
It happened because my project has multiple subprojects/subfolders with their own package.json files. Ensure that module is properly referenced in the subproject's package.json.
In local dev, you might have the dependency cited in your base/global package.json, and thinking it works -- but when you deploy the lambda the npm install that occurs during build does not include the newly required module because its not referenced in the local subproject's package.json.
In the root serverless project folder
npm i --save <npm module name missing>
Well encountered the same issue in our project too.
It was issue in the same of file import.
Our file name xabc.js and in imported as Xabc.js
VScode was not complaining and was showing proper import
For me the problem was that this jmespath library was actually missing(and some others, too) from uploaded node_modules folder.
Verified this by downloading zip(as the source was too big) and did not found there jmespath nor aws-sdk libraries.
Solved it by installing dependencies with npm i and re-uploading lambda with updated node_modules folder.
If 'nodejs' folder is not there in Lambda Layer, create 'nodejs' and any file so that while executing the function, lambda will create zip file with entire node_modules packages inside 'nodejs' folder of Layer. If it is empty it will not execute. I hope it will resolve the issue. In my case it is working fine.
I am starting node app.js in the server directory, and I get the following:
module.js:544
throw err;
^
Error: Cannot find module 'server/server/app.js'
at Function.Module._resolveFilename (module.js:542:15)
at Function.Module._load (module.js:472:25)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3
[nodemon] app crashed - waiting for file changes before starting...
How to fix this? It was working before, and now it's looking for a weird path /server/server instead of just /server.
I just reinstalled node to a more up-to-date version, from 5. to latest stable.
Most likely you try to load your module like so:
require('server/server/app.js')
Node.js then tries to find it somewhere below node_modules. But I suppose, the file is not a dependency but part of your own code. Normally, you would then require it like so (consider the point at the beginning):
require('./server/server/app.js')
This makes Node.js look for the file beginning at the current directory ('.').
This would work in an environment with the following folder structure:
/myfiles/main.js <-- this file contains the `require` statement
/myfiles/server/
/myfiles/server/server/
/myfiles/server/server/app.js <-- this file is being `require`d
I encountered with this issue because I deleted build folder and then try to build the project.
Solution - in my case
I run the tsc --watch that compiled all .ts files to .js
maybe you want to access file app.js,
require('./server/server/app.js')
// to be like this
require('server/server/app.js')
use can using this package
npm i app-module-path
I'm using beaker notebook and would like to use some external node modules - yet because beaker doesn't change the system path to the directory of the currently active file, my attempts to include stream-filter are met with the error:
Error: Cannot find module 'stream-filter'
Error: Cannot find module 'stream-filter'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at eval (eval at processCode (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:45:23), :5:14)
at processCode (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:45:18)
at /opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:32:28
at callbacks (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:164:37)
at param (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:138:11)
at pass (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:145:5)
I'm wondering how to solve this problem. I tried process.chdir('/Users/akivalipshitz/Developer/Computational_Linguistics') to no avail, even though stream-filter is installed in node_modules in the same directory.
So how do people use node modules
The context where the node code is eval'd is in your case
/opt/homebrew-cask/Caskroom//beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js
So require() looks for a module in the node_modules folder there and then recursively up along the parent folders (see docs).
One solution (if you're only working on one project or use this module frequently across all your projects) would be to install your module there:
cd /opt/homebrew-cask/Caskroom//beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/
npm install stream-filter
Another (ugly) approach could be to build a long relative path in your require(). In your case something like:
require('../../../../../../../../../../../../Users/akivalipshitz/Developer/Computational_Linguistics');
Both cases it would mean that your code is not portable to another beaker instance. However, at least until a better solution is proposed this could get you along prototyping.
as of this writing, the current version of Beaker allows you to import npm modules right from the GUI. Just click notebook -> Language Manager -> Javascript, then type the module names into Loaded Libraries. Beaker autocompletes from the npm registry.
This works both in the electron client and the cloud hosted version.