1

I'm developing a component with React.js and the console is throwing the following error:

Failed to compile:

./src/components/file_tree.js
   Module not found: Can't resolve '.src/components/directory.js' in 
'D:\Treebeard\src'

Here you can see the code inside file_tree.js:

import React from 'react';
import ReactDOM from 'react';
import { Directory } from './components/directory.js';

The code inside directory.js:

import React from 'react';
import { TriangleDown } from './components/file_tree.js';
import { FolderIcon } from './components/file_tree.js';
import { formatName } from './components/file_tree.js';
import { renderTree } from './components/file_tree.js';

And here, the App.js code, just in case:

import React from 'react';
import ReactDOM from 'react-dom';
import { SearchEngine } from './components/search_engine.js';
import { FileTree } from './components/file_tree.js';
import { Directory } from './components/directory.js';

I checked the file paths from both files and everything seems okay, but this error is thrown. Am I missing something about the file paths? Both directory.js and file_tree.js are inside './src/components' folder.

App.js is inside './src' folder.

4
  • how are you exporting file_tree.js? Commented Apr 20, 2018 at 14:21
  • @Maxwelll shouldn't matter at this point, you'd get a different error if it didn't actually export those. Commented Apr 20, 2018 at 14:23
  • @JaredSmith if you are by default exporting the component it would matter... Commented Apr 20, 2018 at 14:25
  • 1
    @Maxwelll you and I are working off two different definitions of "matter". You seem to mean "necessary to make the code work" and I mean "would produce the specific error the OP is asking about". AFAICT, we're both correct. Commented Apr 20, 2018 at 14:28

1 Answer 1

1

Since you are accessing file path from same directory. It should be:

file_tree.js:

import React from 'react';
import ReactDOM from 'react';
import { Directory } from './directory.js';

directory.js:

import React from 'react';
import { TriangleDown } from './file_tree.js';
import { FolderIcon } from './file_tree.js';
import { formatName } from './file_tree.js';
import { renderTree } from './file_tree.js';

App.js: It's okay. Since you're accessing components file path from the current directory.

import React from 'react';
import ReactDOM from 'react-dom';
import { SearchEngine } from './components/search_engine.js';
import { FileTree } from './components/file_tree.js';
import { Directory } from './components/directory.js';

For further help, see this post which will help you in relevant case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.