Skip to content

Error: You may need an appropriate loader to handle this file type for shared content #4161

Closed
@renatonmendes

Description

@renatonmendes

I´m working with 2 CRA projects. A shared library of components, and the final application myapp. To build this use case I´ve just built a simple shared component:

import React, { Component } from "react";

class SharedComponent extends Component {
  render = () => {
    return <h1>This is a shared component</h1>;
  };
}

export default SharedComponent;

And on myapp project, I do import and use it:

import React, { Component } from 'react';

import SharedComponent from "shared/src/components/SharedComponent/SharedComponent";

class App extends Component {
  render() {
    return (
      <div>
          <h2>Will load shared component...</h2>
          <SharedComponent/>
      </div>
    );
  }
}

export default App;

To use shared inside myapp, I´ve installed shared at myapp folder as:
$ npm install --save ../shared

Doing that I´ve found that node generated a shared symlink inside node_modules folder.

When running myapp I got this error:

$ npm start
../shared/src/components/SharedComponent/SharedComponent.js
Module parse failed: Unexpected token (4:9)
You may need an appropriate loader to handle this file type.
|
| class SharedComponent extends Component {
|   render = () => {
|     return <h1>This is a shared component</h1>;
|   };

This problem is making me crazy. Seens that is something related to symlinks, but I don´t know how to solve. Please advice.

Sampe code:
usecase.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions