question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent "Relative imports outside of src/" restriction ?

See original GitHub issue

Is this a bug report?

Maybe not

Which terms did you search for in User Guide?

This is related to my previous answer : https://github.com/facebook/create-react-app/issues/1333#issuecomment-428200810

Steps to Reproduce

I have a projet which imports an other “private” package. I am using sass in both packages. The private package is passed to babel only (not node-sass).

I have something like the following in the private module :

// src/component/module.js

import '../styles/module.scss';
// src/styles/module.scss

.module {
    background: url('../images/module.jpg');
}

Then in the main project, if i do this :

// src/index.js

import '@my/module/dist/component/module.js';

everything works fine, but if i do “the same thing” from my sass file :

// src/main.scss

@import '@my/module/dist/styles/module.scss';

i obtain the following error :

Module not found: You attempted to import ../images/module.jpg which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.

Expected Behavior

Both import should fail or success ?

To be able to split my project, i would like to be able to import other packages components and sass files.

Actual Behavior

Importing from sass from sass fails but importing sass from js works.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:30
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

21reactions
iamandrewlucacommented, Dec 22, 2019

@aimadghssisse files outside src/ are not compiled by Babel. Better keep them in src/ folder

7reactions
hugomalletcommented, Oct 11, 2018

Ok finally the issue is different.

The problem is :

  • if imported from javascript, “url()” in sass file are relative to the imported module
  • if imported directly from sass, “url()” in sass file are relative to the main package

Both pass through webpack so the behaviour should be the same ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS import component outside src/ directory
Relative imports outside of src / are not supported. You can either move it inside src/, or add a symlink to it from...
Read more >
The Create-React-App Imports Restriction Outside Of Src ...
Relative imports outside of src are not supported. You can either move it inside src , or add a symlink to it from...
Read more >
Relative imports don't seem to work with create-react-app
I use a bootstrapped setup from create-react-app, and it seems that relative imports for images out of the "src" folder don't seem to...
Read more >
simple dapp with React "issues with solidity"
Module not found: You attempted to import ../build/contracts/SimpleStorage.json which falls outside of the project src/ directory. Relative ...
Read more >
Go Modules Reference - The Go Programming Language
Canonical versions are required outside the main module, and the go ... be found in the directory $GOPATH/src/example.com/repo/sub and would be imported as ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found