Azure Function 'unable to find module' after following installation instructions - node.js

I'm trying trying to use a node module inside my Azure Functions project. I've tried following these instructions several times but still can't use the module I'm trying to bring in.
After bringing in my package.json and running npm install, I can see the node_modules folder (actual modules are located in node_modules/.staging). Upon restarting the function and trying to run it, I get Error: Cannot find module '_____'.
I'm following the instructions correctly. Any suggestions on how to get the modules to work?

You did everything correctly, after npm install, please wait for some time. Modules being in ./staging folder means the installation is still in progress.
You will see added packages prompt in console after the installation is finished.
Update--Avoid long time waiting for module install.
As #brettsam mentioned in comment, with azure-functions-pack tool(also a module), we can place all the modules in a single file, no need to install online and wait. You can search for your function name to find your function scripts if you want to edit after publication.

Related

Is there any way to skip hoisting during yarn build?

Recently I have updated the node version to 16+. Prior to that, I was able to trigger the yarn build command to create the build of my project.
But after installation of node 16+, the yarn build command is throwing the following errors
./lib/view-registration.js
Module not found: Error: Can't resolve 'hoisted/#msdyn365-commerce-modules/wishlist/dist/lib/modules/wishlist-items/wishlist-items.view.js' in 'H:\source\D365_eCommerce\lib'
# ./lib/view-registration.js 5:112769-113063
# ./node_modules/#msdyn365-commerce/bootloader/entry/client.js
# multi ./node_modules/#msdyn365-commerce/bootloader/entry/webpack-public-path.js ./node_modules/#msdyn365-commerce/bootloader/entry/client
It seems like it is trying to pick the module from the hoisted folder.
I am new to this concept so have no idea why it is targeting this folder in spite of this it should pick the module from '#msdyn365-commerce-modules/wishlist/dist/lib/modules/wishlist-items/wishlist-items.view.js' directly.
Any explanation would be appreciated.
How can I force it to not pick the module directly from the hoisted folder and use '#msdyn365-commerce-modules/wishlist/dist/lib/modules/wishlist-items/wishlist-items.view.js' directly
Thanks,
Aman
This issue mainly occurred due to the corrupt version of Node.
The only possible solution for this is to make sure that all the dependencies required for Node (16+) are also installed.
We can either download all the dependencies manually or just need to allow the node itself to download all the dependencies at the time of installation.
Thanks,
Aman

npm error after installing Node.js: Cannot find module 'es6-promisify'

I have installed the latets version of Node.js for Windows. Whatever command I use I always get the same exception, i.e. when I type "npm -v" get this error message:
Cannot find module 'es6-promisify'
How to install "es6-promisify" when NPM is missing "es6-promisify" in the first place?
BTW, during the installation of Node.js a view dependencies try to access protected foldes inside external hard drives for no reason and the last error that stuck forever was the installation of Microsoft Visual Studio Code. It seems to me that those tools cannot be installed without giving 100% access to every folder on every partition you have. This seems wrong to me...
Step 1: Uninstall the NodeJs app from the system
Step 2: Goto the programFiles/nodejs -> delete node_modules folder
Step 3: Reinstall NodeJs app
By following these steps you can fix the issue.
I found out a solution to this issue. I had to unplug all external drives, restart Windows, delete the folder "node_modules" manually and finally I started the Node.js msi to repair the installtion (copies files to node_modules again). After theses steps NPM is working again.
Remember: Reparing the installation without deleting the node_modules folder manually was not sufficient.

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.

When attempting to migrate, Truffle (nodeJS) waffles between two errors?

I'm using truffle with a Node.js project, and when I attempt to migrate the project, I get the following error:
Windows Script Host
However, when I use the suggested fix, which is to rename the truffle.js file to something other than truffle.js (i.e. truffle-config.js), then I get a different error:
Could not find suitable configuration file.
When I rename the configuration file back to "truffle.js", then I get the first error all over again.
The solutions I've tried have included using Windows Powershell to run the program and running the command npm install --force -g truffle, neither of which have worked. I've looked into the recommended solution (https://github.com/trufflesuite/truffle/issues/150), and none of the proposed solutions have worked so far.

Issues installing swiper.js (node.js/grunt noob)

Having issues getting swiper.js to work. Requires grunt/bower. I'm completely new to js generators and am only able to get through about half the walkthrough before running into issues.
When I type $grunt dist into terminal, I get the following response: -bash: dist: command not found
What step am I missing?
Followed the idangerous steps to the letter: http://www.idangero.us/sliders/swiper/plugins/scrollbar.php
I have most often see "X command not found" for one of the following reasons:
The project's Grunt dependencies aren't installed or aren't installed properly
Your Gruntfile is mis-configured or missing
To fix this, first make sure there is a package.json file in your project. This will tell the npm what dependencies the project has and install them accordingly (assuming the package.json file is also configured correctly).
Next, make sure you have installed grunt correctly.
If you're still having issues, open your Gruntfile and search for:
grunt.registerTask('dist
This will show where the "dist" task is being defined. If you for some reason don't find it, then there's your problem. If you do find it, then check the proceeding commands inside square brackets that look like this:
grunt.registerTask('dist', ['clean', 'dist-css', 'copy:fonts', 'dist-js', 'dist-docs']);
'clean', 'dist-css', etc. are all other tasks defined in the Gruntfile, and there could be an issue with those as well.
If there's an issue with your package.json or Gruntfile, then trying re-installing the project with bower and repeat the above steps to ensure that it's not an issue on your end.
If it's not, then something is probably wrong with the author's source code.

Resources