我正在网站上工作并试图包含一个ReactJS组件,我这样做:
import React from "react";
import ReactDOM from "react-dom";
import Layout from "Layout.jsx";
const app = angular.module('myApp');
const reactDirective = app.directive('reactDirective', function() {
return {
template: '<div id="reactapp"></div>',
link: function(scope, el, attrs){
ReactDOM.render(<Layout/>, document.getElementById('reactapp'));
}
}
});
和Layout.jsx
import React from 'react';
export default class Layout extends React.Component {
constructor(props){
super(props);
}
render() {
return (
<div>
This is ReactJS
</div>
);
}
}
然而无论何时编译,它都会给我
ERROR in ./react-app.js
Module not found: Error: Cannot resolve module 'layout.jsx'
谁能告诉我我的代码有什么问题?
答案 0 :(得分:1)
node_modules
中不存在的本地文件导入必须是相对路径。
import Layout from "./Layout.jsx";