使用CucumberJS反应Native:无法找到模块' StyleSheet'

时间:2018-03-18 21:38:32

标签: react-native babeljs cucumberjs

我试图在与Babel的反应原生应用中使用CucumberJS。当我尝试运行它(./node_modules/.bin/cucumber-js --require-module babel-register)时,我得到:

Error: Cannot find module 'StyleSheet'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.get StyleSheet [as StyleSheet] (/Users/diego/code/test-app/node_modules/react-native/Libraries/react-native/react-native-implementation.js:98:29)
    at Object.<anonymous> (/Users/diego/code/test-app/App.js:16:16)
    at Module._compile (module.js:660:30)
    at loader (/Users/diego/code/test-app/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/diego/code/test-app/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/diego/code/test-app/features/step_definitions/steps.js:3:1)
    at Module._compile (module.js:660:30)

从我搜索的内容来看,它与Facebook&#34; haste&#34;有关。进口的风格,但无法解决它。当我运行项目时,它工作得很好。

这是我的.babelrc

{
  "presets": [
    "babel-preset-react-native-stage-0/decorator-support"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

features/step_definitions/steps.js

import { Given } from 'cucumber';
import React from 'react';
import App from '../../App';

import renderer from 'react-test-renderer';

// steps...

package.json

{
  "name": "my-test-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-react-native-stage-0": "^1.0.1",
    "babel-register": "^6.26.0",
    "cucumber": "^4.0.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "16.2.0"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "node node_modules/jest/bin/jest.js"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "react": "16.2.0",
    "react-native": "0.52.0"
  }
}

App.js

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
        <Text>Changes you make will automatically reload.</Text>
        <Text>Shake your phone to open the developer menu.</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

0 个答案:

没有答案