Creating a dev environment from existing website with nodejs - node.js

So I've used Node.js in the past before, but I've never created a development environment from a pre-existing website. And now I have to. Plus, the previous developer worked in another state and used an iMac and developed in Coda. We were able to get all the files to my current workspace but I am trying to create the project in Visual Studio with Node Tools and am running into an issue. I fairly certain that its some kind of routing/config/setup issue but have not been able to suss it out and I've been rooting through package.json and config files for days.
All files are in the same relative directory from the root yet, and I've updated all packages and adjusted the code accordingly (I believe for the updated packages). However, when I try to start the site up, I run into this issue.
Debugger listening on [::]:5858
T:\IT\Website\ComfortCo(Dev)\ComfortCo(Dev)\views\index.jade:1
(function (exports, require, module, __filename, __dirname) { extends global_layout
^^^^^^^
SyntaxError: Unexpected token extends
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Press any key to continue...
The site uses jade with express and this is a pretty basic function of jade layouts. So I do not know why there is a Syntax Error.
Any ideas?
Update
So I was told that I did not have the most up-to-date versions of Node except I installed the most current version of Node when I installed Node Tools for VS and the pathing is correct.
However, when I ran npm list and npm list -g they came back with nothing even though my projects npm repository shows a whole list of packages installed and up-to-date. So I can only conclude that their is some pathing issue here. However, I have never configured Node paths. I've always just left them default. Any guidance here?

The extends keyword is supported since Node version 4.x - see:
http://node.green/#ES2015-functions-class-extends
It seems that you may be running an older version of Node but of course it's hard to tell because you provided no information about your runtime environment whatsoever.

Related

Routing and custom widget issues after upgrading dojo and node versions

We are facing couple of issue with dojo framework after we upgrade our node and npm version, please find the details below and it will be of great help if you could please provide inputs on how this can be resolved
Application structure: We are using dojo framework application build on node and npm, we are using grunt along with dojo and npm node modules
Issue: We started facing issues with grunt 2 months back without any changes to our code, we were not able to do npm install, logs were provided below for your reference
issue logs:
--------------------------------------------------------------------------------------
module.js:478
throw err;
^
Error: Cannot find module 'has'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (...\v6.14.4\node_modules\grunt-cli\node_modules\is-core-module\index.js:3:11)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
--------------------------------------------------------------------------------------
module.js:478
throw err;
^
Error: Cannot find module 'ini'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/jenkins/workspace/module/node_modules/global-prefix/index.js:14:11)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
--------------------------------------------------------------------------------------
Version we were using:
node: 6.14.4
npm: 3.10.10
grunt-cli: 0.1.13
python: 2.7
Visual studio: 2013
dojo node modules we were using:
"dijit": "dojo/dijit#1.9.9"
"dojo": "dojo/dojo#1.9.9"
"dojo-util": "dojo/util#1.10.4"
"dojox": "dojo/dojox#1.9.9"
Based on the suggestions received we have upgraded node and npm version along with grunt, dojo and some of the other node modules, please find the version we upgraded to
node: 16.13.2
npm: 8.19.3
grunt-cli: 1.4.3
python: 3.10
Visual studio: 2022
dojo node modules we updated:
"dijit": "^1.17.3"
"dojo": "^1.17.3"
"dojo-util": "^1.17.3"
"dojox": "^1.17.3"
After the above upgrade changes we are seeing couple of issues with routing and custom widgets
Issue 1:
We are using router.go function to navigate between pages, here we implemented replacements and query as parameter but from one of our view the navigation is not working, though the url path is getting changed on click of button the page is not refreshed and still shows the existing one, it stays on same page if same button is clicked but when other button is clicked the url path changes and navigation happens this time, issue is only with first time navigation and the same router.go implementation is working in other places in application.
We have tried resetting the router, reinitializing and reload, but reloading is refreshing whole page which is not a considerable solution.
Issue 2:
We have a multiselect calendar to select date with right and left arrows using custom widget dijit base css, we have writter our own implementation with table, tr and td, after the upgrade the table classes are not getting applied and calendar format is broken
Any inputs of suggestions here are much appreciated or if you can please provide what was changed between the versions we upgraded (might be some documentation if we can find some where, we tried looking at dojo community but couldn't find any) please reply if you need further information, Thanks a lot in advance.
We have tried resetting the router, reinitializing and reload, but reloading is refreshing whole page which is not a considerable solution.

npm run gulp primordials not defined

I'm trying to run npm run gulp and I'm coming up with this primordials is not defined error (I have also added the npm-shrinkwrap.json file as suggested which gets updated after running npm install but it doesn't fix my primordials is not define error):
> gulp-tutorial#1.0.0 gulp
> gulp
fs.js:47
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:47:5
at req_ (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:143:24)
at Object.req [as require] (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
Node.js v17.0.1
Any suggestions 🙌 ?
Primordials are used by Node.js internal modules and are not accessible to end user scripts. (That's their entire point for existing. Otherwise, you could modify Object.prototype and end up affecting Node.js internals, causing weird crashes and things like that.)
The module that is giving you this error is the natives module. The page for the package says:
This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs#4.x.
Sounds like it's at that point where it's broken. Use npm ls natives to find out what's using it. (You might need to be in the /Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main directory when you run the command.) From there, you can try to figure out how to get rid of it.
Another possibility would be to try downgrading to an earlier version of Node.js to see if it works with that version.
The problem was with the versions not matching up. I also had 2 NodeJS installation paths and that was throwing things off.
I uninstalled them all, started from the beginning and used brew to reinstall.
Then checked that the versions were all compatible.
I also had to install node-sass and referred to this compatibility table to get the correct version - https://github.com/sass/node-sass#node-version-support-policy
Now its working and I can get on developing :) As of today Im running Node v17.0.1 Npm v8.1.0 Gulp cli v2.3.0

Firebase cloud functions suddenly returns #grpc module error

I'm finding Firebase Cloud Functions to be quite unreliable.
What happened:
I had one function working as expected (function A), already deployed and okay.
As I was building another one (function B), unrelated to A, cloud functions logs started reporting the following error:
Error: Cannot find module '#grpc/grpc-js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/node_modules/google-gax/build/src/grpc.js:37:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Maybe I messed something up. So I removed function B and deployed again. The errors still kept appearing, and function A was no longer working.
How I tried to solve:
Removed the node_modules folder and ran npm install again.
Installed, again, the grpc module with npm install --save grpc.
Nothing has solved the problem.
Any ideas on what am I doing wrong? And also on how to avoid this from happening again?
Thanks in advance for any help!
I could not figure the reason for this behavior.
However, by following Paul Kinlan's suggestion, the error went away (no changes in the functions whatsoever).
npm install
npm rebuild --build-from-source google-cloud
I also performed a npm update to make sure I had all the latest packages, following Doug's comment in my question.
If anyone figures out the cause of this error, please drop a note so we can avoid it in the future.
Try deleting the cloud function from the console and then upload it again.

Use ES6 with npm in CLI mode

I am trying to get CKEditor in my project with a custom build.
However, my problem is more general, so feel free to answer even if you don't use CKEditor.
Following the instructions to generate a custom build, I am getting a syntax error when running npm run build in terminal:
my/build/path/bin/create-entry-file.js:12
const { bundler } = require('#ckeditor/ckeditor5-dev-utils');
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
Npm fails with a bunch of text and the above error. I believe this error is generated due to modern ECMAScript syntax, which is not recognized in my local machine.
However, the build I am trying to generate is there, complete and ready. Also, some other documentation of theirs, indicate more import {...} from syntax. This means that they are able to generate the build without the need of external packages (otherwise they would be in the package.json dependencies).
So, my question is, how do I install the software needed that will allow my npm to recognize and execute modern ES syntax ?
I am running on Ubuntu 16, with the lastest npm version: 5.6.0.
Thanks in advance, let me know if I can provide more information
Can you please check the version of Node on your computer?
Run in the terminal
node -v
You need to have at least 6.4 as your Node.js version according to this list on your computer
Here you have a link where you get and update to the newest version of Node 8.9.4 for different platforms. In your case check Linux
https://nodejs.org/en/download/

Cannot find module connect/utils when installing node+express

I just installed node by cloning the git repo + make && make install. I then installed npm, and used npm to install express (seems like it fetches connect automatically since it's a dependency). However, when trying to start a simple express example i get the error message:
Error: Cannot find module 'connect/utils'
at Function._resolveFilename (module.js:219:11)
at Function._load (module.js:171:25)
at require (module.js:246:19)
at Object.<anonymous> (/home/yngve/local/node/lib/node/.npm/express/1.0.3/package/lib/express/response.js:16:13)
at Module._compile (module.js:302:26)
at Object..js (module.js:308:10)
at Module.load (module.js:234:31)
at Function._load (module.js:201:10)
at require (module.js:246:19)
at Object.<anonymous> (/home/yngve/local/node/lib/node/.npm/express/1.0.3/package/lib/express/index.js:52:1)
Seems someone has the same problem here: http://groups.google.com/group/express-js/browse_thread/thread/287086bd30f79cf1/adbb5c669872e45a
but the conclusion seems to be that one needs connect installed (which I have).
I've checked that I have the following files at least:
/home/yngve/local/node/lib/node/.npm/connect/0.5.8/package/lib/connect/utils.js
/home/yngve/local/node/lib/node/.npm/express/1.0.3/node_modules/connect/connect/utils.js
Anyone have a clue?
Resolved
Added
require.paths.unshift('<path_to_node>/lib/node/connect');
But the newest rev. is fixed, so this shouldn't really be necessary (see answer below).
It seems like it was a bug in express. Installing the latest version, 1.0.5, fixed this problem for me.
It sounds like you don't have your require path including your npm directory. Use require.paths to modify that.
Some more info:
http://jherdman.github.com/2010-04-05/understanding-nodejs-require.html

Resources