lelandrichardson / react-primitives

Primitive React Interfaces Across Targets
MIT License
3.09k stars 108 forks source link

Compilation issue when used with Next.js #116

Closed msand closed 6 years ago

msand commented 6 years ago

I've encountered an issue while evaluating react-primitives in Next.js

{ /Users/jannegylling/IdeaProjects/seaber/with-react-native-web-app/node_modules/react-native-web/dist/exports/StyleSheet/ReactNativeStyleResolver.js:17
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.react-native-web/dist/exports/StyleSheet/ReactNativeStyleResolver (webpack:/external "react-native-web/dist/exports/StyleSheet/ReactNativeStyleResolver":1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 4d331b16180318579799:21:0)
    at Object../react-primitives/lib/injection/react-native-web.js (react-primitives/lib/injection/react-native-web.js:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 4d331b16180318579799:21:0)
    at Object../react-primitives/lib/index.web.js (react-primitives/lib/index.web.js:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 4d331b16180318579799:21:0) sourceMapsApplied: true }

I think the same cause has been at issue here: https://github.com/styled-components/styled-components/issues/1176

Can be fixed by requiring StyleRegistry from the react-native-web/dist/cjs folder instead https://github.com/lelandrichardson/react-primitives/blob/c2f0545cbcc4b25447c1edf93b8ca20b8e2824b9/src/injection/react-native-web.js#L19