社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

npx ts lint在Docker中运行时找不到模块“typescript”

Mnebuerquo • 4 年前 • 465 次点击  

我正在为api项目的node/typescript设置一个停靠的开发环境。目标是在Docker中运行所有的东西,而不是在主机上安装任何节点、NPM或模块。这是为了将node和所有模块的所有版本与其他项目隔离开来。

/节点

docker run \
    -it \
    -p "8080:80" \
    --rm \
    -w "/app" \
    -v "$(pwd):/app" \
    "node:10" "$@"

/净现值

#!/bin/sh
./node npm $@

/净现值

#!/bin/sh
./node npx $@

./package.json包

{
  "name": "testapi",
  "version": "0.0.1",
  "description": "a hello world api",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "npx ts-node src/app.ts",
    "lint": "npx ts-lint --project src $@"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^6.2.0",
    "fastify": "^1.13.2",
    "ts-node": "^7.0.1"
  },
  "devDependencies": {
    "@types/node": "^10.12.15",
    "ts-lint": "^4.5.1",
    "typescript": "^3.2.2"
  }
}

[编辑]

我用 ./npm install 建立我的节点模块。节点模块位于共享卷中,因此在移除容器后,它将在主机上保持。这样我就不需要Dockerfile来构建图像。

[/编辑]

当我运行lint命令时,出现以下错误:

testapi$ ./npx ts-lint -i
10: Pulling from node
Digest: sha256:5af431757f84bf7878ff72447eb993fc37afcd975874fff13278157bf83661e6
Status: Image is up to date for docker-remote.registry.kroger.com/node:10
npx: installed 32 in 2.883s
Cannot find module 'typescript'

我认为这与模块分辨率有关,但我不确定。我看到人们在全球安装typescript,但这意味着我必须使用dockerfile而不是stock节点映像。我不介意为dev使用Dockerfile,但我认为应该有一种方法可以在不这样做的情况下使这个工作。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46537
 
465 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Mnebuerquo
Reply   •   1 楼
Mnebuerquo    5 年前

所以我找到了答案。不明显,我偶然发现了。

我已经安装了 ts-lint (见上面的package.json),我看到了一个引用 tslint (没有连字符)。

所以我搬走了 TS绒布 并安装 特斯林特 就像冠军一样。我不知道有什么区别,但是连字符的那个在我的项目配置中不起作用。另外,不带连字符的安装版本号高于带连字符的。

查看包含工作依赖项的my new package.json:

{
  "name": "testapi",
  "version": "0.0.1",
  "description": "a hello world api",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "npx ts-node src/app.ts",
    "lint": "npx tslint --project ./ 'src/**/*.ts?(x)' $@"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^6.2.0",
    "fastify": "^1.13.2",
    "ts-node": "^7.0.1"
  },
  "devDependencies": {
    "@types/node": "^10.12.15",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  }
}

当在Docker容器中运行时,仅使用public node:10映像即可。它不需要dockerfile来安装任何全局依赖项。