这是一个非常讨论的话题,但我从未找到解决方案。
因此,您可能知道,当我的容器中有一个卷并且我yarn install使用 Dockerfile 中的 a安装我的依赖项时,Yarn 将node_modules在我的容器上创建一个具有root:root访问权限的文件夹。
这种方法有两个问题(在本地/开发环境中):
该node_modules文件夹仅在我的容器中,但主机的代码编辑器(我的是 VSC)可能需要此文件夹才能正常工作。比如你没有,VSC会骂你他找不到导入的模块……
如果主机想要安装一个包,yarn add ...他将不得不重新启动并重建要安装的包的容器。
所以我想出了另一个想法,如果我CMD在 Dockerfile 中安装依赖项(或文件中command服务的属性)怎么办docker-compose。因此,Docker 将与主机共享node_modules. 但这是主要问题,node_modules有root:root权限访问,所以如果你的主机的用户名被命名mint并且不具有相同的名称uid,gid你将需要运行 root 访问命令来安装/删除依赖项(例如sudo yarn add ...)。
这是我当前的配置:
docker-compose.yml:
version: '3.7'
services:
app:
container_name: 'app_DEV'
build: .
command: sh -c "yarn install && node ./server.js"
volumes:
- ./:/usr/src/app
ports:
- 3000:3000
tty: true …Run Code Online (Sandbox Code Playgroud) 我有此错误,但我真的不知道为什么:
Window.getComputedStyle的参数1不实现接口Element
HTML:
<div class="reveal"></div>
Run Code Online (Sandbox Code Playgroud)
JavaScript / jQuery:
var reveal = $('.reveal');
reveal.css('margin', '10px');
var resulte = window.getComputedStyle(reveal, 'margin');
Run Code Online (Sandbox Code Playgroud) 当接口通过类型指定为函数的返回时,它似乎接受额外的属性。
例如,如果我有一个名为 的空接口MyInterface、一个函数的类型 :type MyFunction = () => MyInterface;和一个函数const myFunction: MyFunction = () => ({ foo: 'bar' }),它不会引发该foo属性的任何错误。
以下是一些示例:
// No 'age' property
interface Human {
name: string;
}
const human: Human = {
name: '',
age: 0 // Error
}
type HumanCreator = (name: Human['name'], age: number) => Human;
const humanCreator: HumanCreator = (name, age) => ({
name,
age // No error. Why?
});
const humanCreatorr: HumanCreator = (name, age): Human …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Jest 和 Bazel 来测试我的 Typescript 代码。
的 repo上有一个示例rules_nodejs,但它只是使用原始 Javascript 文件:https ://github.com/bazelbuild/rules_nodejs/tree/master/examples/jest
我的目标是使用ts_library规则(来自)编译我的 Typescript 代码,然后将其传递给 Jest 规则(我对 Jest 使用与的存储库rules_nodejs示例中相同的规则)。rules_nodejs
这是玩笑规则:
# //:rules/jest.bzl
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")
def jest_test(name, srcs, deps, jest_config, **kwargs):
"A macro around the autogenerated jest_test rule"
args = [
"--no-cache",
"--no-watchman",
"--ci",
]
args.extend(["--config", "$(location %s)" % jest_config])
for src in srcs:
args.extend(["--runTestsByPath", "$(locations %s)" % src])
_jest_test(
name = name,
data = [jest_config] + srcs + deps,
args …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 TypeOrm 连接到 Mongodb Atlas。
这是我的ormconfig.json:
{
"type": "mongodb",
"host": "cluster0-****.mongodb.net",
"port": 27017,
"username": "testUser",
"password": "******",
"database": "test",
"useNewUrlParser": true,
"synchronize": true,
"logging": true,
"entities": ["src/entity/*.*"]
}
Run Code Online (Sandbox Code Playgroud)
然后当我尝试出现createConnection()此错误时:
(node:10392) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-****.mongodb.net:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND cluster0-****.mongodb.net cluster0-****.mongodb.net:27017]
实际上,我找不到有关如何执行此操作的任何信息。
我的端口对吗?如果它不是我在哪里可以找到它?我在哪里可以在 Atlas 上找到我的数据库名称?
是否可以作为infer重载函数的参数?
例如:
type MyFunction = {
(key: "one", params: { first: string }): void;
(key: "two", params: { second: string }): void;
}
type MyFunctionParams<T extends string> = MyFunction extends (
key: T,
params: infer P,
) => void
? P
: never;
// should be `{ first: string }`
type OneParams = MyFunctionParams<"one"> // never
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用adminmongo访问docker上的 mongo 数据库。
这是我的 docker-compose.yml
version: '3'
services:
mongo:
image: mongo
volumes:
- ~/data:/data/db
restart: always
expose:
- 6016
adminmongo:
image: mrvautin/adminmongo
expose:
- 1234
links:
- mongo:mongo
Run Code Online (Sandbox Code Playgroud)
当我做一个docker-compose up一切正常时,adminmongo 也返回给我这个:adminmongo_1_544d9a6f954c | adminMongo listening on host: http://localhost:1234
但是当我去localhost:1234我的导航器时告诉我这个页面不存在。
这是我的docker ps回报:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c27d4a89254 mrvautin/adminmongo "/bin/sh -c 'node ap…" 38 seconds ago Up 33 seconds 1234/tcp iris_adminmongo_1_544d9a6f954c
2a7496a8c56a mongo "docker-entrypoint.s…" 40 …Run Code Online (Sandbox Code Playgroud) 好的,我最近安装了 Ubuntu 来进行 Web 开发,我注意到了两件事:
$ sudo例如,我需要用于编辑文件(在 www-data: ... file/s 中) $ sudo atom / var / www / index.html。如果我不使用这个命令,atom 会说我没有权限。
我还需要使用$ sudo一些命令,例如对于$ git commit -m新提交,我需要使用$ sudo. 但这可能是因为 git 没有正确的权限。
我尝试过$ sudo chown -R www-data: anatole(anatole 是我在 ubuntu 上的用户名),但是 WordPress 需要 www-data: www -data 权限才能添加插件...
我认为我是根本原因,我可以使用 sudo 命令,并且我是这台计算机上的唯一用户。
因此,如果有人有解决方案,我真的很想知道。
我尝试做这样的事情:
function setup() {
createCanvas(500, 250);
//frameRate(1);
}
function draw() {
background(50, 50, 150);
translate(10, 10);
for (let i = 0; i < 30; i++) {
rect(i*15, 0, 10, random(30, 120));
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.min.js"></script>Run Code Online (Sandbox Code Playgroud)
但我想“冻结”这个画布,所以如果我加载页面,我将在 30 到 120 之间的随机高度上有 30 个 rect()。
我有一个<input type="text" />作为搜索栏的<form>.
因为它是一个搜索栏,所以/search?q=thingIWantToSearch当提交表单时,用户应该被重定向到类似于 : 的路由。
目前我正在做,location.href但我认为这不是一个好方法(或者是吗?)
这是我的代码:
<script>
let inputValue = '';
const handleSubmit = () => {
// there should be some parsing before putting it in the url, but it's not the subject
location.href = `/search?q=${inputValue}`;
}
</script>
<form on:submit|preventDefault={handleSubmit}>
<input type="text" bind:value={inputValue} />
<button type="submit">submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
那么如何在表单提交时正确重定向用户?
我正在尝试从打字稿导入一个 json 文件(是的,我resolveJsonModule在我的 tsconfig 中使用了该标志)。问题是,我不知道如何将这个 json 文件提供给ts_library(这也适用于任何其他非.ts&.tsx文件,例如 a .env)。ts_library总是告诉我他找不到我的 json 文件。
例如,如果我有这样ts_library的BUILD.bazel:
ts_library(
name = "src",
srcs = glob(["*.ts"]),
deps = [
"@npm//:node_modules",
]
)
Run Code Online (Sandbox Code Playgroud)
有了这个index.ts:
ts_library(
name = "src",
srcs = glob(["*.ts"]),
deps = [
"@npm//:node_modules",
]
)
Run Code Online (Sandbox Code Playgroud)
这test.json:
{
"foo": "bar"
}
Run Code Online (Sandbox Code Playgroud)
它会给我这个:
index.ts:1:18 - error TS2307: Cannot find module './test.json'.
Run Code Online (Sandbox Code Playgroud)
我想我需要以某种方式在deps我的规则中添加 json 文件。但我不知道该怎么做,因为 deps 不接受像//:test.json …
typescript ×4
javascript ×3
bazel ×2
docker ×2
mongodb ×2
jestjs ×1
jquery ×1
linux ×1
node.js ×1
p5.js ×1
permissions ×1
processing ×1
sapper ×1
svelte ×1
typeorm ×1
ubuntu ×1