Cannot find module 'express' cloudfoundry node08 during deployment - node.js

While deploying the nodejs application in cloudfoundry.. it s giving error "Cannot find module 'express'".. Appreciate any help in this regard.. It is very simple hello world program.. Even the package.json is pretry simple.. Is there any cloudfoundry specific changes that needs to be done..
Thanks

Make sure to have modules already installed using "npm install". Or, do "npm shrinkwrap", Create package.json file w/ {"ignoreNodeModules": true} to ask CF to install modules in the cloud. See: http://www.youtube.com/watch?v=rCrXhNGDhhY&list=UU0ZYS0Y7b5oiVLvxGf4magw&index=4&feature=plcp

Related

How do I use Quokka with imported typescript files?

I've installed ts-node with NPM install, and tinkered with this for hours, I cant find any other documentation on the website as to why its not working. A quick google search has also turned up nothing; which is why I'm SURE its some small thing I'm missing. ts-node has also been installed globally AND in the project folder I'm getting the following error:
To import TypeScript files from quokka, `ts-node` module must be installed. 
It is also recommended to install `tsconfig-paths` module for tsconfig.json paths mapping. 
You may install the modules in your project or into quokka global folder by running `npm install ts-node tsconfig-paths` command inside the `~/.quokka/` folder. 
at ​​​Module.load​​​ ​internal/modules/cjs/loader.js:653​
at ​​​tryModuleLoad​​​ ​internal/modules/cjs/loader.js:593​
at ​​​Function.Module._load​​​ ​internal/modules/cjs/loader.js:585​
at ​​​require​​​ ​internal/modules/cjs/helpers.js:25​
at ​​​Object.<anonymous>​​​ ​frontEnd/datrix/src/app/Logic/DeveloperTemplate.ts:1​
at ​​​Module._compile​​​ ​internal/modules/cjs/loader.js:778​
does anyone have some insight on how this can be done?
I figured it out, I had to open the project file in vs code, not the directory above it.

Node package dependencies on IBM Cloud Foundry - require/module is not defined (Package not loading)

I am working on an application via the toolchain tool on IBM Cloud and editing the code via the Eclipse Orion IDE. As I am not accessing this through my local cli, my understanding is that in order to so call npm install {package}, I would just need to include the package in the package.json file under dependencies and require it in my app. However, when I load the application, I get the require is not defined indicating that the package has not been installed. Moreover, the require() is being used in the app.js file with the application being launched but not from files in my public directory.
After playing around further, it seems it might have to do with the way the directory tree is being traced as the error is only thrown in subdirectories. For example, require('express') works in app.js which is in the main directory ./ but fails when it is called in test.js in ./subdirectory/test.js. I feel like I'm missing something painfully simple like configuration of endpoint or something.
I've been searching around but I can't seem to find how to get the packages loaded, preferably without using the cli. Appreciate any pointers. Thanks!
Update: After playing around further, I am also getting module is not defined error when trying to require from another file in the same directory. For example module.exports = 'str' returns this error. While trying to require('./file') returns the require is not defined. It might have to do with how node is wrapping the functions?
Update 2: Tried "start": "npm install && node app.js" in package.json but no luck. Adding a build stage which calls npm install before deployment also does not work
Update 3: After adding npm install build stage, I am able to see that the dependencies have been successfully built via the logs. However, the require is not defined error still persists.
Update 4: Trying npm install from my CLI doesn't work as well even though all packages and dependencies are present
Update 5: Running cf restage or configuring cache via cacheDirectories does not work as well
Opened a related question regarding deployment here
Found out my confusion was caused due to me not realizing that require() cannot be used on the client side unless via tools such as Browserify.

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.

Ember Cli not compiling with broccoli-emblem-compiler

I am trying to set up this repository locally https://github.com/lrdiv/ember-soundcloud and i have come across to this issue with broccoli-emblem-compiler. See the image in attached
From my understanding the broccoli-emblem-compiler is not able to compile my emblem templates and i don't know how i can figure it out.
These are all the steps i have done to install and set up the project with Ember-Cli
ember new soundcloud
ember install:addon ember-cli-coffeescript
ember install:npm broccoli-emblem-compiler
I have deleted the app folder and replace with the project https://github.com/lrdiv/ember-soundcloud that i have cloned
then i have installed the other node modules required
ember install:npm broccoli-static-compiler
ember install:npm broccoli-merge-trees
ember install:npm install body-parser
and at the end i run
ember server , and in my terminal i get that error i have attached.
What can i do now to sort this out? What's really the problem?
I did many things to try to fix this. One was replacing the project broccoli-emblem-compiler with this line in the project settings:
"broccoli-emblem-compiler": "git+https://github.com/cascalheira/broccoli-emblem-compiler.git"
At some time the error went away, I think it was when I used this repository. It is mentioned in the other issues.
I ran into problems with broccoli-emblem-compiler, but just had success with ember-cli-emblem-hbs-printer -
https://github.com/201-created/ember-cli-emblem-hbs-printer
I was able to solve this by specifying a version of emblem.js in my package.json file.
Specifically, I added the following line:
"emblem": "0.3.14"

How to start an appfog locomotive.js app?

I'm using the node framework locomotive.js on an appfog instance. Installing this caused a slew of errors and I couldn't get the app to start. Reviewing the help materials and working with appfog support we were able to resolve that the issue had to do with the package.json file and specifically the invocation of lcm server.
What is correct package.json property?
You might check out https://github.com/hakaider/locomotive-appfog-sample
I just cloned it into my directory, ran npm install, then af update [my app name here] and it just worked.

Resources