Npm start is not relative to root


#1

Hi,
I am a new to web development.
Versions:
Atom 1.20.1
npm version 3.10.10
node version 6.9.1
webpack version 3.6.0
running npm start from terminal terminal produce the following error:
./src/components/Init.js Module not found: Can’t resolve ‘helpers/localProfile’ in 'C:\Users…\project\src\components’
The error is obvious its try to pick up a file according to current file path BUT ‘helpers/localProfile’ is in different directory.
I can fix it by adding ‘…/’ to the import but then I will need to change it in the whole project.
If I run npm start in windows shell everything works as expected.
I tried several solutions like setting NODE_PATH = src/ in the.env file but it didn’t work. and (rootpath)
I believe it related to Atom as I tried several terminal plugins and all of them produce the same error.
I will really appreciate your help regarding this issue.


#2

Could you post a screenshot of your workspace?


#3

Thanks a lot.
Project Structure:


Error Description:(Unfortunately I can put only one image )

./src/components/Init.js
Module not found: Can’t resolve ‘helpers/localProfile’ in ‘C:\Users\Michael\Documents\dogiz2\src\components’

Init file(beginning):
import React from 'react';
import { connect } from 'react-redux';
import { getLocalProfile } from 'helpers/localProfile';
import { profile } from 'actions/user';
import { authState } from 'actions/app';

class Init extends React.Component {
    componentDidMount() {
        let {setInitUser} = this.props;
        setInitUser();
    }

    render() {
        let {children} = this.props;

        return (
            <div style={{minWidth : "1000px", height : "100%", minHeight : "100%"}}>
                {children}
            </div>
        )
    }
};

#4

If you’re in the same directory in the terminal, I don’t know why it would have different results.


#5

As you can see the error … and the error is obvious . It simply looks for the files relative to the directory it was called from. whele npm start
from windows CLI works as expected…


#6

Can I see your terminal window?


#7

npm start from windows (works as expected):


#8

Sorry my bad executed it from another directory (but it doesn’t change the result just made several tests).


#9

if I makecreate-react-app and thennpm start everything is working as expected.
My case is slightly different I do the create-react-app than I delete all the content and clone repository into that folder.
The images i provided are from cloned repository (of-course that repository was also created with create-react-app so it should work as it works on windows)


#10

What about the Atom terminal?


#11

npm start


#12

after few seconds:


#13

Everything else seems to be happening correctly.


#14

its a question?


#15

ok, I solved the problem:
npm install -D cross-env
"start": "cross-env NODE_PATH=src npm-run-all -p watch-css start-js",
Somehow .env didn’t functioned as well … strange…or maybe junior mistakes.
Thanks a lot DamnedScholar