Implementing ReactJS into Angular App

angularjs reactjs webpack

30 观看

1回复

31 作者的声誉

I am working on a website and tried to include a ReactJS component and I'm doing it like so:

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'));
        }
    }
});

and the Layout.jsx

import React from 'react';
export default class Layout extends React.Component {
    constructor(props){
      super(props);
    }
    render() {
        return (
            <div>
                This is ReactJS
            </div>
        );
   }
}

However whenever it compiles, it gives me
ERROR in ./react-app.js Module not found: Error: Cannot resolve module 'layout.jsx'
Can anyone tell me what's wrong with my code?

作者: SirSoDerp 的来源 发布者: 2017 年 12 月 27 日

回应 1


1

19370 作者的声誉

决定

Imports of local files that don't live in node_modules have to be relative paths.

import Layout from "./Layout.jsx";
作者: Andy Ray 发布者: 2017 年 12 月 27 日
32x32