insin / nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Other
5.57k stars 331 forks source link

Usage with SSR React projects. #464

Open haani104 opened 6 years ago

haani104 commented 6 years ago

This issue is a:

REPRO REPOS https://github.com/ctrlplusb/react-universally

Is the version of nwb you're using installed globally or locally? - Globally

➜  react-universally git:(master) ✗ node -v
v8.11.1
➜  react-universally git:(master) ✗ npm -v
6.1.0
➜  react-universally git:(master) ✗ nwb -v
v0.21.5

Hi, I have created a npm module (using nwb new react-component), which is published on npm and can be installed by typing npm i react-loading-button-check

The issue is whenever I am importing the button, i.e. import LoadingButton from 'react-loading-button-check' in any server side rendering(SSR) react project, I always get the below error

buttonstyle.css:1
(function (exports, require, module, __filename, __dirname) { .button-comp {
                                                              ^

SyntaxError: Unexpected token .
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/haani/learnspace/react-universally/node_modules/react-loading-button-check/lib/index.js:17:1)

However it runs fine when used with any other non SSR React projects.

I am tryig to build a React library that can also be used by SSR React projects. Please help/guide.

lean commented 5 years ago

same issue here

haani104 commented 5 years ago

@lean If the above is a blocker for you, I suggest you look into other options for creating React library. Like this one https://github.com/transitive-bullshit/create-react-library

lean commented 5 years ago

Yes, it is a blocker. So I will try your suggestion. Thanks