Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIles imported from symlinked folders are treated different then others #2553

Closed
dschu-lab opened this issue Jun 17, 2017 · 9 comments
Closed

Comments

@dschu-lab
Copy link

dschu-lab commented Jun 17, 2017

Description

I'm currently facing problems with importing files from symlinked folders.

Consider this example filestructure

app/
├── core/
│   ├── configuration/
│   ├── Player.js
│   └── GameServer.js
├── client/ << create-react-app
│   ├── build/
│   ├── public/
│   └── src/
│       ├── components/
│       │   └── Game.js
│       └── lib/
│           └── core/ -> ../../../core/ (SYMLINK)

/core/Player.js

export default class Player {
    constructor(
        name,
        color,
        position={x:0, y:0, z:0},
        velocity={x:0, y:0, z:0},
        rotation={x:0, y:0, z:0}
    ) {} 
[...]

/client/src/components/Game.js

import React, { Component } from 'react';
import Player from '../../../lib/core/Player';

class Game extends Component {
    constructor(props) {
        console.log(Player);
    }
}

export default Game;

When having this file in /client/src/lib everything works fine, but when moving the file to the subfolder core, which is a symlink to the root of the project, things start to break.
I'm unfortunately still trying to figure out, what exactly goes wrong, but it must have to do with the webpack configuration, I think. Importing normal configuration objects from this symlink work like a charm, but something is happening (or not happening), when importing classes.

When importing from /client/src/lib console.log outputs the following:

function Player(name, color) {
        var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { x: 0, y: 0, z: 0 };
        var velocity = arguments.length > 3 && arguments[3] !== …

While, when importing from the symlink /client/src/lib/core console.log outputs the following:

 class Player {
    constructor(name, color, position={x:0, y:0, z:0}, velocity={x:0, y:0, z:0}, rotation={x:0, y:0, z:0}) {....}

Expected behavior

Since I'm technically still in /src I would expect that the code is treated the same way, even though I'm importing from a symlinked folder.

Actual behavior

So some compiling doesn't happen, when importing from symlinks. Is this correct? Should this happen?

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected):
xxx@0.1.0 /WebstormProjects/xxx/client
└── react-scripts@1.0.7
  1. node -v: v6.11.0
  2. npm -v: 3.10.10

Then, specify:

  1. Operating system: macOS 10.12.5
  2. Browser and version: Google Chrome Version 58.0.3029.110 (64-bit)

Reproducible Demo

Will provide a demo if needed.

@dschu-lab
Copy link
Author

dschu-lab commented Jun 19, 2017

Also, when trying to run the build script, it throws this error

static/js/main.dc8f221c.js from UglifyJs
Unexpected token: name (Landscape) [../core/Landscape.js:5,0][static/js/main.dc8f221c.js:140702,6]

This file is written in ES6 using class. How am I able to tell the build script to handle the files the way they should? I've added a .eslintrc inside the ./core folder, but it seems to be ignored.

Update
Found this article on stackoverflow. I've moved everything into a /src folder, creating an ES5 /build and updated my symlink. Worked like a charm 🍾 🥂

@Timer
Copy link
Contributor

Timer commented Jun 19, 2017

Hmm, that's odd! react-scripts should yell at you for importing out of src/; we need to review this.
I imagine we'd want it to work for symlinks.

@Timer Timer added this to the 1.0.x milestone Jun 19, 2017
@dschu-lab
Copy link
Author

Thanks for looking into this. If you need a reproducable demo, just ping me. 👍

@gaearon
Copy link
Contributor

gaearon commented Jun 22, 2017

I'm afraid but "want it to work" @Timer means we should crash (since we don't currently support this use case). So not sure if it will help you 😛

@Timer
Copy link
Contributor

Timer commented Jun 22, 2017

Yeah, to clarify we'd basically make symlinks within src/ that point outside of something in src/ error out since it's not supported.

I did not mean to imply we'd try compiling these sources (unless that's something we should do (?)). That seems more of a webpack-specific thing, however.

@1st
Copy link

1st commented Mar 27, 2018

The same issue mentioned here #3547

@1st
Copy link

1st commented Mar 27, 2018

Finally I found a workaround. You can run a watch process to compile your shared library and use it as symlink in your project. Here is my gist.

@Timer Timer modified the milestones: 2.0.x, 2.x Sep 26, 2018
@Timer Timer removed this from the 2.x milestone Nov 2, 2018
@stale
Copy link

stale bot commented Dec 2, 2018

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 2, 2018
@stale
Copy link

stale bot commented Dec 8, 2018

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

@stale stale bot closed this as completed Dec 8, 2018
@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants