小编Sh *_*eeb的帖子

装饰器不支持函数调用,但调用了“FileTypeModule”

尝试设置ngx-formly-material-file,但出现错误:装饰器不支持函数调用,但调用了“FileTypeModule”

我试图导出 FileTypeModule,但得到了同样的错误

export const fileTypeModule = FileTypeModule.forRoot();

@NgModule({
  imports: [fileTypeModule]

})
Run Code Online (Sandbox Code Playgroud)

angular-formly angular ngx-formly

14
推荐指数
2
解决办法
5799
查看次数

tsconfig 导致 [ERR_REQUIRE_ESM]:必须使用 import 加载 ES 模块

我已经知道如何解决该错误[ERR_REQUIRE_ESM]: Must use import to load ES Module

\n

但我注意到这是由设置来引用引起的,paths我不知道确切的原因。node_modulestsconfig.json

\n

tsconfig.json

\n
{\n  "compileOnSave": false,\n  "compilerOptions": {\n       "paths": {\n          "*": ["node_modules/*", "types/*"]                  \xe2\x80\x8b\n       }\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

删除 "*": ["node_modules/*", "types/*"]喜欢这个问题,但我想知道为什么?

\n

tsconfig-paths特别是在注册ts-node然后运行时会出现此错误webpack -c webpack.config.ts

\n

tsconfig.json:

\n
{\n  "compileOnSave": false,\n  "compilerOptions": {\n       "paths": {\n          "*": ["node_modules/*", "types/*"]                  \xe2\x80\x8b\n       \xe2\x80\x8b}\n  },\n  "ts-node": {\n     "require": ["tsconfig-paths/register"]\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

完整的错误跟踪:

\n
(node:6087) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: …
Run Code Online (Sandbox Code Playgroud)

node.js typescript webpack ts-node

6
推荐指数
0
解决办法
1223
查看次数

将 tsconfig-paths 与 es 模块一起使用

我有一个使用 commonjs 模块的打字稿项目,我用ts-node它来运行它并在运行时tsconfig-paths解析tsconfig.compilerOptions.paths。

现在我希望我的项目迁移到使用es模块,所以我做了一些更改:

  • 添加type: module到 package.json
  • 更改module: commonjs为ES2022tsconfig.json
  • 将命令更改ts-node为node --loader ts-node/esm

现在一切都工作正常,但似乎tsconfig-paths在 esm 中不起作用。

最小复制品:

在这两个项目中:

  • 运行npm run build以测试使用带有 esm 的 typescript 进行编译
  • 运行npm start测试ts-node
  • 运行npm start:paths测试ts-node​tsconfig-paths

node.js typescript tsconfig ts-node tsconfig-paths

6
推荐指数
0
解决办法
1526
查看次数

异步管道向子组件发送“空”值

我想将一个值传递给子组件。这个值是一个 Observable,所以我使用异步管道。

<child [test]="test$ | async"></child>
Run Code Online (Sandbox Code Playgroud)

test$ 只是一个普通的可观察变量,它在一段时间(3000 毫秒)后发出值,模拟对服务器的 API 请求。

this.test$=timer(3000).pipe(
      mapTo("value")      
 )
Run Code Online (Sandbox Code Playgroud)

在子组件中,我只想检查test值

@Input() test: any;

constructor(){
    console.log("child/test", this.test); //null
    setTimeout(()=>console.log("child/test (timeout)", this.test),4000) //value

   if(this.test){
     //maintain and check `this.test`
     //this code will not run, because at this point `this.test` is null.
     //we don't know the exact time that `this.test` will have a value
     //this causes that `this.test` is wrong

      this.checked=true 
     }
  }

Run Code Online (Sandbox Code Playgroud)
<div *ngIf="checked">{{test}}</div>
Run Code Online (Sandbox Code Playgroud)

我不想更改测试类型Observable并订阅它。我想直接接收最终值。我根本不想修改编辑组件。

使用ChangeDetectorRef手动触发变化检测器是不

@Input() test$:Observable

constructor(){
  this.test$.subscribe(v=>this.test=v)
}
Run Code Online (Sandbox Code Playgroud)

我还做了这个 …

observable rxjs angular-pipe angular async-pipe

4
推荐指数
4
解决办法
5460
查看次数

在 webpack 中使用 node-loader 安装“sharp”模块时出现问题

我使用sharpand webpackwithnode-loader但出现此错误:

\n
D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:150011\n  throw new Error(error);\n  ^\n\nError:\nSomething went wrong installing the "sharp" module\n\nnode-loader:\nError: The specified module could not be found.\nD:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server/33c1e48f049ce3285905e286d212a201.node\n\n- Remove the "node_modules/sharp" directory then run\n  "npm install --ignore-scripts=false --verbose" and look for errors\n- Consult the installation documentation at https://sharp.pixelplumbing.com/install\n- Search for this error at https://github.com/lovell/sharp/issues\n\n    at Object.EmBj (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:150011:9)\n    at __webpack_require__ (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:27:30)\n    at Object.Tbcg (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:251632:15)\n    at __webpack_require__ (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:27:30)\n    at Module.dMKD (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:324313:63)\n    at __webpack_require__ (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:27:30)\n    at Module.mWHM (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:405859:77)\n    at __webpack_require__ (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:27:30)\n    at Module.WXK/ (D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server\\express.js:271250:65)\n    at …
Run Code Online (Sandbox Code Playgroud)

node.js node-modules webpack sharp

3
推荐指数
1
解决办法
1万
查看次数

如何将js对象转换为点表示法字符串

我有一个像这样的 javascript 普通对象:{a: {b: 1} } 并且我想将其转换为像这样的点符号字符串a.b = 1

用例:

将对象发送到纯文本环境(例如 cli)或作为 url 参数。

javascript

-3
推荐指数
1
解决办法
1965
查看次数