My folder structure is as follows:
In my App.Js (which is under the components folder), I have:
import variables from '/src/EnvVariables/variables.json';
However, I get an error:
You attempted to import /src/EnvVariables/variables.json which falls
outside of the project src/ directory. Relative imports outside of
src/ are not supported. You can either move it inside src/, or
add a symlink to it from project's node_modules/.
I have also tried:
import variables from './src/EnvVariables/variables.json';
import variables from '/src/EnvVariables/variables.json';
import variables from '/src/EnvVariables/variables.json';
import variables from '/EnvVariables/variables.json';
import variables from './EnvVariables/variables.json';
All either give the above error, or say "can't resolve file".
This file is in a folder that is under /src, as they said. But it still tells me it must be under the /src/ directory. How can I import my variables.json file? I don't want to just put it under "components", i prefer to better organize it.
Have you tried to import with the relative path? (with one or more ../ sections)
import variables from "../EnvVariables/variables.json"
Of course, if you prefer absolute paths you can setup https://webpack.js.org/configuration/resolve/, but I believe for first, you should try the first solution
Do ../../ before path
source={require('../../assets/eating.png')}
if you just need to import your any file to a component : (just follow this steps)
Simply you can create a .env file in src directory .
In that .env file you need to add this line only NODE_PATH = src/
Then you can write import "Home.css" (your file name will be here) to a component from src, it will take it easily.
Run the program again , then you will get the same error, but take
it easy and just you have to do fully start your program with the npm start from
a new terminal.
Related
When I try to import my Function from a lower directory it doesn't work.
It works if both file's are in the same directory but if they are not, it fails saying there is no Module named "GameFunctions"
So this would work
./game.py
./GameFunctions.py
But this wouldn't
./etc/game.py
./GameFunctions.py
I tried using the code
from GameFunctions import * when both were in the same directory. it worked
Tried the same thing while they were in different directories
but I got the error
Traceback (most recent call last):
File "d:\Projects\MyScripts\PYTHON\Test\tes\game.py", line 1, in <module>
from GameFunctions import *
ModuleNotFoundError: No module named 'GameFunctions' ```
It can apparently read the file though, since it causes a problem if I rename a def in GameFunctions, it says the def is not defined in game.py
Ohk a much easier solution do one thing write your input statement like this
from parentdirectory.GameFunctions import *
This should solve your error
you can add folder of GameFunctions.py file to the python path:
import sys
sys.path.append('/Path/to/GameFunctions-Folder')
from GameFunctions import *
I am having trouble with D's package.d feature. I have my package.d file:
module dew;
public
import dew.util;
I then have util.d:
module dew.util;
struct Size
{
int width;
int height;
}
When I try to use it in another project, it gives me this error:
I know that this should work, because projects on GitHub use it, specifically bindbc-sdl.
Your code is correct. By the error message I'm assuming your project layout with DUB probably looks something like this:
dew/
dub.sdl/dub.json
source/
package.d
util.d
However this would be incorrect. By default DUB only uses import folders instead of specifying all input source files, so the compiler attempts to discover the files from the import paths in the filesystem. The compiler dumped the import paths it searches in in your error screenshot.
The rough compiler equivalent to what it's doing right now is (see dub -v)
dmd source/app.d -Isource -I../dew/source
You need to imagine that the path whatever is written in there is invisible to the compiler, so the dew/source/ path is just some opaque string the compiler doesn't interpret. Now all that the compiler sees is a package.d and util.d in its search paths. However for imports from folders to function, they need to correspond to the filesystem layout, i.e. you need to have a folder named dew where your files are stored in.
So a module named dew.util would correspond to dew/util.d
And your package dew would correspond to dew/package.d
So for your dub project that means essentially that you need to move all your source files into
dew/
dub.sdl/dub.json
source/
dew/
package.d
util.d
Alternatively it would be possible to manually specify all files one-by-one where the compiler can look them up because of the module declarations at the top of the file, however you lose the convenience of module names being mapped to filesystem paths, which might be something other community-made D source tools and IDEs are expecting. On the command line that would be equivalent to
dmd source/app.d ../dew/source/dew/package.d ../dew/source/dew/util.d
In my src folder, I have assets/styles folder where my global scss files are.
In my index.scss I import them like this
#import 'assets/styles/colors.scss';
#import 'assets/styles/links.scss';
#import 'assets/styles/basics.scss';
And then in index.js, I import compiled index.css
Problem: In basics.scss I'm using variable from colors.scss and getting an error Undefined variable: \"$black\".
And the same happens in components scss files if they use variables from that file. I really don't want to import colors in every single component. Is there a way to make these 3 files global?
To work with scss in reacting I'm using Adding a CSS Preprocessor (Sass, Less etc.) (Since moved here).
UPD
Use partials when importing parts into index.scss
#import 'assets/styles/colors';
#import 'assets/styles/links';
#import 'assets/styles/basics';
The filenames should be
_colors.scss
_links.scss
_basics.scss
You can read more about this in the SASS docs under the Partial section.
can not import a python program in the same folder
C:\Users\User_Unknowed\Desktop\Marvin
So i have started to just look if it where the fun.py that could be wrong or it can't just be find which now print error so i need help.
My code on test67.py:
start of code
import os.path
if not os.path.exists(fun.py):
print("Alarm")
if os.path.exists(fun.py):
print("import")
end of code
Anything of an solution would be lovely. Answer as quickly as possible please, thx.
To import a file inside of the same directory use:
import fun
To locate the file in a specified directory use os.walk:
import os
def find(nameofFile, path):
for root, dirs, files in os.walk(path):
if nameofFile in files:
return os.path.join(root, nameofFile)
if you find this file is not in the same directory you can use sys.path.insert() to add the path of the file you want to import:
import sys
sys.path.insert(0, pathtoFile)
from fun import *
Hope this helps.
From the looks of the go documentation, they make it seem like you have to put code you're working on under your $GOPATH-- is that correct?
I would like to set up a test project in a dir under my ~/Documents, but everytime i run go install example/newmath (like in the test example) it says the following--
λ MacBook-Air src → go install example/newmath
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
can't load package: package example/newmath: import "example/newmath": cannot find package
Does that mean that i need to reset my $GOPATH/$GOROOT? I'm lost.
No need to setup GOROOT in the common situation. GOPATH, OTOH, should be set (and exported).
I would recommend to start with
export GOPATH=$HOME
Then just put a package having import "whatever" into $GOPATH/src/whatever.
You can refine your GOPATH to your needs later, when you get used to how things work with the Go build system (go {build, install}). One can have even multiple items in $GOPATH, but I really don't think it's a concern in the beginning, and sometimes never.