NextJS build error - ReferenceError: navigator is not defined - node.js

I'm running into this special error message while trying to build a simple NextJS application (using npm run build):
> Build error occurred
ReferenceError: navigator is not defined
at /cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:18:19
at /cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:11:83
at Object.<anonymous> (/cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:14:2)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/cdk-next/next-frontend/node_modules/easymde/src/js/easymde.js:2:18) {
type: 'ReferenceError'
}
info - Collecting page data .
I don't know who codemirror is, or why it's not letting me build my project. From reading around I gather that this issue occurs with NextJS when trying to build a project on the server side instead of the client side, because the project does not have access to a window or navigator. In that case, what should I do? The tutorial I'm following seems to breeze through this step just fine, so should I just look at their package.json and downgrade all of my packages? Any advice would be appreciated.

The error was with my import of import SimpleMDE from "react-simplemde-editor" (located in create-post.js of the repo link above).
I implemented the solution proposed by modikum here: https://github.com/dabit3/next.js-amplify-workshop/issues/21.
Now the project builds successfully.

Related

stt.node version incompatible with electron

I'm getting below error when trying to launch the application.
This is after I deleted node_modules and re-ran npm i to pull packages again
App threw an error during load
node_modules/electron/dist/resources/default_app.asar/main.js:113
Error: Cannot find module '/home/korodarn/projects/mygit/sight-words-solid-electron/node_modules/stt/lib/binding/v1.4.0/linux-x64/electron-v17.4/stt.node'
Require stack:
- /home/korodarn/projects/mygit/sight-words-solid-electron/node_modules/stt/index.js
- /home/korodarn/projects/mygit/sight-words-solid-electron/dist/main/index.cjs
- /home/korodarn/projects/mygit/sight-words-solid-electron/node_modules/electron/dist/resources/default_app.asar/main.js
-
at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
at Function.n._resolveFilename (node:electron/js2c/browser_init:249:1105)
at Module._load (node:internal/modules/cjs/loader:785:27)
at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/korodarn/projects/mygit/sight-words-solid-electron/node_modules/stt/index.js:24:17)
at Module._compile (node:internal/modules/cjs/loader:1116:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
I've tried electron-rebuild ( invoked with node_modules/.bin/electron-rebuild ) and it completes successfully but it seems to only rebuild the canvas dependency based on the output.
I am not able to follow the coqui stt documentation well enough to know where to go next.

firebase functions, javascript: how to test locally if all packages are specified in package.json

I get this error message when deploying my firebase function:
Function execution started
Provided module can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '#docsndata/testing-stub-graphql'
Require stack:
- /workspace/local_deps/workflow/core2/dist/cjs/recordManagement/StubRecordManagement.js
- /workspace/local_deps/workflow/core2/dist/cjs/index.js
- /workspace/local_deps/cyclepositive/webhook2/dist/cjs/onWebBooking.js
- /workspace/local_deps/cyclepositive/webhook2/dist/cjs/index.js
- /workspace/lib/index.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/loader.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/workspace/local_deps/workflow/core2/dist/cjs/recordManagement/StubRecordManagement.js:9:32)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
Could not load the function, shutting down.
I know what the root cause is - I have a dependency that is not in package.json
My question is: how do I test this locally? When I do this:
firebase emulators:start --only functions
my function starts. So it seems like the deploy process of the function does something different, like actively check for missing packages. How can I check I have that right, before even attempting to deploy?
Edit #1 Rewording and retagging to reflect fact that am using firebase functions, not google cloud functions directly.
Edit #2 I tried deploying again this morning, after three of the above failures last night, and now it works. Is the deployment process flaky? Regardless, question still stands: what is the best way to test the firebase deploy process locally?

ReferenceError: window is not defined in godash

I am trying to build a board game and want to use godash to create a board state and update it. I have successfully installed godash into my package.json, but when I require it in the back-end, in my server.js (the file in which I run my server),
var godash = require ('godash');
and I run node server.js, the CLI responds with this error:
ReferenceError: window is not defined
at Object.<anonymous> (C:\Users\Chidi\gt\projects\Chess-vs-Go\node_modules\godash\dist\godash.js:1:194)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Chidi\gt\projects\Chess-vs-Go\game_state\go_state.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
I've seen various "window is not defined" questions on this site in my effort to solve this problem, and the general solution seems to be that the code should be used in a browser environment. However, this is godash, an npm package that is to be used in the back-end. I have tried updating node.js and npm to their latest versions, but the problem still persists. I feel like I am making an obvious error that I can't see, because I went to the github page for godash and did not find any closed or open issues similar to this one. Does anyone know what the issue is, and how I can resolve it?
So, upon further research, I found that there are ways to use npm packages in the browser (e.g via browserify) This allowed me to use godash in the browser, where it was looking for a window object.

Function load error: Code in file index.js can't be loaded. firebase functions issue

I am trying to deploy new functions in my firebase project but it started showing an error. I have 5 functions in my index.js file and at any given point, 4 functions are getting deployed and one is throwing this error.
⚠ functions[whenUserIsAdded]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-functions'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/index.js:1:79)
at Module._compile (module.js:570:32)
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)
This happens every time to any one of the 5 functions and this happens in random. I deployed the same code about 2 hours ago and it went smooth. Now after adding some console.log statements, it is showing this error at random with a function.
Can anybody help me with this issue. Thanks in advance.
Also, I am on the blaze plan.
Ok. I think I found the issue. I was having firebase-functions V0.6.3. I believe that was depreciated. Hence it was not working I updated my package.json to the following and it worked. Because functions is still in Beta, I dont think we can do anything about this.
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",

Use edge js on openshift

I'm trying to run C# on my OpenShift cartridge with Edge.js. It runs really good on my Windows PC and I would like to have it running on the cloud.
I'm guessing it runs on a Linux environment but I'm not shure.
At first I tried to make it work with my MSSQL DB and than move on to the C# assembly.
Nevertheless I'm doing the same steps as how I've got it to work on my Windows machine but I'm getting thesame errors over and over again.
I've added edge and edge-sql to my npm and my package.json.
Then I've make a simple count to my MSSQL DB.
When I'm running it locally it works great. Than I push it to OpenShift and I tail the application, because the front-end gives me an Error 503, and the next thing I know the following error makes me keepings my hands in my hair.
Error: The edge native module is not available at /var/lib/openshift/54d26260fcf
933d05e00021a/app-root/runtime/repo/node_modules/edge/build/Release/edge.node. Y
ou can use EDGE_NATIVE environment variable to provide alternate location of edg
e.node. If you need to build edge.node, follow build instructions for your platf
orm at https://github.com/tjanczuk/edge
at Object.<anonymous> (/var/lib/openshift/54d26260fcf933d05e00021a/app-root/
runtime/repo/node_modules/edge/lib/edge.js:33:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/lib/openshift/54d26260fcf933d05e00021a/app-root/
runtime/repo/server.js:5:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
/var/lib/openshift/54d26260fcf933d05e00021a/app-root/runtime/repo/node_modules/e
dge/lib/edge.js:33
throw new Error('The edge native module is not available at ' + builtEdge
Could somebody help me to fix this error or maybe explain to me why it could / wont work?
If edge requires a native windows environment to run C#, then it will not work on OpenShift, which runs on Red Hat Linux.

Resources