0

I have to use a JS library called 'react-armor' here for my web project. So, created a React powered server as instructed here.

The server is up and running. But, in order to use the react-armor library, the code specifies to import the library into the project JS:

import { obfuscateClassNames } from 'react-armor';

*as in the readme.md tutorial of react-armor github

But, how could I use the package react-armor (examples given in the readme.md) into my react server? I mean, how to integrate the github repo to my server? Just using import something from 'react-armor', so where should react-armor exist?

Update 1:

Added react-armor dependency in server package.json file.

But, sudo npm install --save react-armor gives me errors.

npm http GET https://registry.npmjs.org/react-armor
npm http 404 https://registry.npmjs.org/react-armor
npm ERR! TypeError: Cannot read property 'latest' of undefined
npm ERR!     at next (/usr/share/npm/lib/cache.js:687:35)
npm ERR!     at /usr/share/npm/lib/cache.js:675:5
npm ERR!     at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
npm ERR!     at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.13.0-87-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "react-armor"
npm ERR! cwd /home/local/unixroot
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! type non_object_property_load
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/local/unixroot/npm-debug.log
npm ERR! not ok code 0

Even after adding the dependency in package.json file, the import doesn't work.

This is my package.json in my react server folder:

   {
      "name": "react-tutorial",
      "version": "0.0.0",
      "private": true,
      "license": "see LICENSE file",
      "description": "Code from the React tutorial.",
      "main": "server.js",
      "dependencies": {
        "react-armor": "elierotenberg/react-armor",
        "body-parser": "^1.4.3",
         "express": "^4.4.5"
      },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/reactjs/react-tutorial.git"
  },
  "keywords": [
    "react",
    "tutorial",
    "comment",
    "example"
  ],
  "author": "petehunt",
  "bugs": {
    "url": "https://github.com/reactjs/react-tutorial/issues"
  },
  "homepage": "https://github.com/reactjs/react-tutorial",
  "engines" : {
    "node" : "0.12.x"
  }
}

Update 1:

It seems like some dependency errors here. But, is it possible to run this on Tomcat instead of NodeJS? Why does everyone recommend using NodeJS for ReactApp instead of Tomcat, despite React being a client side rendered JS lib?

1 Answer 1

1

If it's an NPM package, you would run npm install --save react-armor (--save if you want to add it to your down package's dependencies). It will download it and save it into a ./node_modules folder. Node will automatically look in that path (in addition to other preset locations) to find that module.

If it's not hosted on NPM, you can pull it in from GitHub by adding this to your package.json file.

"dependencies": {
  "react-armor": "elierotenberg/react-armor"
}

Where the url is user/repo. You would still need to run npm install to actually download it.

Sign up to request clarification or add additional context in comments.

7 Comments

My guess is they didn't put it on NPM. I just did a quick search and couldn't find it. Odd. Try adding it via GitHub link (2nd part of my post).
Yes, I added the same in package.json, still the import doesn't happen. Will it be downloaded into the server lib?
Can you post a copy of your package.json? Thanks!
Yes, sure. Updated. I'm trying to import the react-armor library into the default react tutorial application as mentioned here. Thanks.
I think it might be your version of npm. You can either upgrade by running npm install -g npm or maybe try changing the URL to "git+https://github.com/username/repository.git".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.