Visual Studio Code Docker React TypeScript 语法高亮

huangapple go评论56阅读模式
英文:

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?

Visual Studio Code Docker React TypeScript 语法高亮

Visual Studio Code Docker React TypeScript 语法高亮

Visual Studio Code Docker React TypeScript 语法高亮

答案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 installyarn。你的镜像通常不会受到影响。

英文:

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

huangapple
  • 本文由 发表于 2023年5月17日 17:40:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定