How to create a React component to publish on NPM?


Written by burczu

  • Philippe Leefsma

    Kick ass post Mate! Thanks a bunch!

  • Peter Hollingsworth

    A couple of things —

    1) this command…
    npm install /path/to/your/package/react-component-npm-1.0.0.tgz
    needs to be

    npm –save install /path/to/your/package/react-component-npm-1.0.0.tgz
    Use the –save option if you want it written to the package.json file.

    2) When you change the output to dist/index.js, you will also need to edit index.html in the root directory to point to the new file.

    3) Were you really able to install the “npm pack” output and get it to work? Can I ask — what did the import or require command look like that you used in the host project? I have not had any luck with this — I get strange errors like “Uncaught ReferenceError: React is not defined”

    • Ian Kettle

      I’m getting the same “Uncaught ReferenceError: React is not defined” error