process not defined when using npm react package - javascript

I am including npm react package in a script in the following way:
var react = require('react');
I am using node however when i do this and run my local node server i get the following error in the browser:
checkPropTypes.js:12 Uncaught ReferenceError: process is not defined
at Object.6../lib/ReactPropTypesSecret (checkPropTypes.js:12)
at s (_prelude.js:1)
at _prelude.js:1
at Object.8../checkPropTypes (factoryWithTypeCheckers.js:17)
at s (_prelude.js:1)
at _prelude.js:1
at Object.7../factoryWithTypeCheckers (factory.js:16)
at s (_prelude.js:1)
at _prelude.js:1
at Object.24../ReactElement (ReactPropTypes.js:16)
I'm not sure what is causing this error. I have tried to set NODE_ENV environmental variable using:
export NODE_ENV='development'
If anyone could shed any light on why i am getting this error that would be helpful.
Thanks in advance.

Related

Require module inside a WebWorker in React

i am trying to import an npm module inside my React Web Worker using const package = require('package-name').
But it gives me the following error :
Uncaught (in promise) ReferenceError: require is not defined
How can i use a module inside a worker, is there a native way or some way to bypass it?
I am using NodeJS v18.10.0, Webpack v5.73.0.
I think your question is related to
Client on Node.js: Uncaught ReferenceError: require is not defined
please look at it , you might solved your problem

Cannot read properties of undefined (reading 'isAbsolute')

I was editing this program yesterday and it worked fine the whole time. The program is created using parcel, today when started up the script and the dev server was broken. This is the error i recived:
*Uncaught TypeError: Cannot read properties of undefined (reading 'isAbsolute')
at parcelRequire.../node_modules/tar/lib/strip-absolute-path.js.path (strip-absolute-path.js:2:9)
at newRequire (main.fb6bbcaf.js:47:24)
at localRequire (main.fb6bbcaf.js:53:14)
at parcelRequire.../node_modules/tar/lib/write-entry.js.minipass (write-entry.js:39:27)
at newRequire (main.fb6bbcaf.js:47:24)
at localRequire (main.fb6bbcaf.js:53:14)
at parcelRequire.../node_modules/tar/lib/pack.js.minipass (pack.js:28:20)
at newRequire (main.fb6bbcaf.js:47:24)
at localRequire (main.fb6bbcaf.js:53:14)
at parcelRequire.../node_modules/tar/lib/create.js../high-level-opt.js (create.js:6:14)*
I cant seem to find anyone else with the same error. This is strip-aboslute-path.js 2:9 where the error happens:
//unix absolute paths are also absolute on win32, so we use this for both
const { isAbsolute, parse } = require('path').win32
I’ve tried:
npm install, npm install tar, npm i -g npm and
changing the names of folders in the Path to the src file that included "å, ä, ö",
Would love get this running again, any suggestions on what to try next?
Solved: This probably happened due to me trying to access a variable named x and vscode auto adding "import {x} from tar" at the top of the js file. When removing the import the program was working again.

How to read Javascript errors?

I'm trying to run a basic Vue JS app, on my local machine, that uses the materialize-css navbar (https://materializecss.com/navbar.html). On running this app in the terminal, I'm getting the following error.
This relative module was not found:
* ./components/Navbar in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
What is this error trying to say? How to correct this?
The problem was with the name of my navbar file. In my code, it was "Navbar" while in my local directory was "NavBar".

iView not defined error while trying to import it

I'm trying to import iView UI on my VueJS project with Webpack inside main.js.
import iView from 'iview'
Then:
Vue.use(iView)
And console shows up an error saying
Uncaught ReferenceError: iView is not defined
I added iview plugin by doing npm i iview -D on my project.
Why this isn't working? Any ideas? Maybe some package.json issues? whenever i run npm run dev it compiles everything fine, no errors, no warnings.
Okay, after some hours of attempts, I found out I had two ways of including this lib.
By either doing:
import iView from 'iview/dist/iview'
This one would throw a warning about types not defined for this, but if you do it like so:
const iView = require('iview')
It will work like a charm! Hope this helps to anyone who's under the same situation I was.

Importing variable from another file into route file of node.js

I'm attempting to pass a prompt box variable into my route file of a node.js application, but I'm having issues having the variable be recognized. The main prompt variable "test" is in a javascript file called mainclient.js, and I'm attempting to get it into my index.js file. I've attempted to export it as so:
In mainclient.js I have:
exports.Test = test;
and in my index.js, I've included:
var mainclient = require('../public/javascripts/mainclient');
and then call it by using:
var prompt = mainclient.test;
When I attempt to start the node, I'm getting an error stating:
ReferenceError: $ is not defined
Due to the first line in my mainclient.js file being:
$(document).ready(function(){
Anyone know a way to get this error corrected or another way that I can get the variable from mainclient.js into index.js? Any help would be greatly appreciated. Thanks!
Edit:
I should add, I've attempted to import jquery in both files by including the proper header link,however, I then get an error stating:
"SyntaxError: Unexpected token <" when attempting to start the node. jquery is imported in the main.js file for the node though.

Categories

Resources