英文:
Visual Studio Code Docker React TypeScript syntax highlighting
问题
I have a React & TypeScript & Docker project set up and it all works great. However, my Visual Studio Code is reporting various errors, like missing types and similar.
How to make the highlighting work?
英文:
I have a React & TypeScript & Docker project set up and it all works great. However, my Visual Studio Code is reporting various errors, like missing types and similar.
How to make the highlighting work?
答案1
得分: 0
在使用 Docker 时,即使你的文件夹与 Docker 镜像内的文件夹通过卷键同步,node_modules
并不是一个被同步的文件夹。但是 VSCode 需要它们在本地,没有它们,它无法进行索引等操作。
通常,一个 Docker Compose 文件看起来像这样(你提供的那个是完全可以的):
version: '3.1'
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
在 node_modules
上的卷选项 "prevent" 了本地和镜像之间的同步。所以,我只需在本地文件夹中运行 npm install
或 yarn
。你的镜像通常不会受到影响。
英文:
While using docker, even if your folder is synchronised with a folder inside your docker image with volumes key, the node_modules is not a folder that is synchronized. But VScode, need them locally, without them, it can't do all this indexing things.
Generally, a docker-compose file look like this (the one you provide is perfectly fine)
version: '3.1'
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
The volume option on node_modules "prevent" synchronization on this folder between local and the images. So, I simply do an npm install
or yarn
in the local folder.
Your image will normally not be impacted
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论