uwcirg / helloworld-react-client-sof

0 stars 4 forks source link

Relative imports are not supported #2

Open ivan-c opened 2 years ago

ivan-c commented 2 years ago

In my attempt to support development with docker, I've been trying to store node dependencies outside the git checkout.

When I tried installing node_modules into the parent directory of the git checkout (see notes), I got the below error.

From this SO question, it sounds like a restriction from create-react-app.

Relative import error:
Attaching to sof-client-dev_frontend_1
frontend_1  | 
frontend_1  | > hello-world-react@0.1.0 start /opt/app
frontend_1  | > rescripts start
frontend_1  | 
frontend_1  | ℹ 「wds」: Project is running at http://192.168.32.2/
frontend_1  | ℹ 「wds」: webpack output is served from 
frontend_1  | ℹ 「wds」: Content not from webpack is served from /opt/app/public
frontend_1  | ℹ 「wds」: 404s will fallback to /
frontend_1  | Starting the development server...
frontend_1  | 
frontend_1  | Failed to compile.
frontend_1  | 
frontend_1  | ./src/components/Summary.js
frontend_1  | Module not found: You attempted to import ../../node_modules/cql-worker/src/cql.worker.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
achen2401 commented 2 years ago

@ivan-c I saw that the error was related to importing the cql worker lib in node_modules folder, Does this resolve the error?

ivan-c commented 2 years ago

@ivan-c I saw that the error was related to importing the cql worker lib in node_modules folder, Does this resolve the error?

Yup, thank you!

If I understand correctly, you fixed the issue by replacing a relative import with an absolute one. However, I was wondering if you won't be able to use relative imports at all, and if that's even a problem.

Since the immediate problem is solved, feel free to close this issue after your PR is merged

achen2401 commented 2 years ago

If I understand correctly, you fixed the issue by replacing a relative import with an absolute one. However, I was wondering if you won't be able to use relative imports at all, and if that's even a problem.

@ivan-c For importing node_modules components/libs, I am able to use both absolute path and relative path in my own local instance (which is not docker built). But I can see the flaw in using the relative path if the location of the node_modules directory has changed as in this situation.