2016-09-24 31 views
2

我想创建一个utils.js,其中包含我的许多React组件使用的所有实用功能。在React-Rails应用程序中的React ES6组件之间导出/导入实用程序功能

我尝试导出和导入实用程序类为我的阵营组成是这样的:

// utils. js 
export default class Utilities; 


// myComponent.es6.jsx 
import someFunction from 'Utilities'; 

我收到类似这样的错误:

Uncaught ReferenceError: require is not defined(anonymous function) 
Uncaught ReferenceError: exports is not defined 

如何建立一个独立的事业页然后可以导入到我的React组件中?

我很困惑 - 感谢您提供的任何帮助!

回答

1

你的答案可能是here。基本上,我相信这是因为importexportrequire尚未与Rails和所有浏览器完全兼容。这就是为什么在大多数应用程序中他们使用Babel transpiler或常见的JS内容。让我知道,如果这有助于

+0

谢谢,oreoluwa!对此,我真的非常感激。 –

相关问题