Ask coding questions

← Back to all posts
Import error in subfolder
h
pkme (0)

When I import a module from a file in the source root it works, but when I import from a subfolder(scripts) typescript complains. How can I connect the subfolder's files to be able to import node modules?

Voters
pkme (0)
Comments
hotnewtop
JohnBarnhart (11)

There's no need to mess with your PYTHONPATH or sys.path here.

To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:

from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:

from .dirfoo1.foo1 import Foo1
from .dirfoo2.foo2 import Foo2

pkme (0)

Thanks @JohnBarnhart , so in the above example, how should I rewrite:

import Phaser from "phaser"

JohnBarnhart (11)

@pkme instead of it like "phaser" it is 'phaser'

pkme (0)

@JohnBarnhart I'm not sure I follow, I changed the quotes to single quotes with no different, still "cannot find module"

JohnBarnhart (11)

@pkme :\

I guess i'm not as experienced as I thought. Sorry man. I don't have anything else.