尝试设置ngx-formly-material-file,但出现错误:装饰器不支持函数调用,但调用了“FileTypeModule”
我试图导出 FileTypeModule,但得到了同样的错误
export const fileTypeModule = FileTypeModule.forRoot();
@NgModule({
imports: [fileTypeModule]
})
Run Code Online (Sandbox Code Playgroud) 我已经知道如何解决该错误[ERR_REQUIRE_ESM]: Must use import to load ES Module
但我注意到这是由设置来引用引起的,paths我不知道确切的原因。node_modulestsconfig.json
tsconfig.json
\n{\n "compileOnSave": false,\n "compilerOptions": {\n "paths": {\n "*": ["node_modules/*", "types/*"] \xe2\x80\x8b\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n删除 "*": ["node_modules/*", "types/*"]喜欢这个问题,但我想知道为什么?
tsconfig-paths特别是在注册ts-node然后运行时会出现此错误webpack -c webpack.config.ts
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}\nRun 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) 我有一个使用 commonjs 模块的打字稿项目,我用ts-node它来运行它并在运行时tsconfig-paths解析tsconfig.compilerOptions.paths。
现在我希望我的项目迁移到使用es模块,所以我做了一些更改:
type: module到 package.jsonmodule: commonjs为ES2022tsconfig.jsonts-node为node --loader ts-node/esm现在一切都工作正常,但似乎tsconfig-paths在 esm 中不起作用。
最小复制品:
es 模块项目,从 commonjs 项目派生出来,但经过修改以使用 es 模块
在这两个项目中:
npm run build以测试使用带有 esm 的 typescript 进行编译npm start测试ts-nodenpm start:paths测试ts-nodetsconfig-paths我想将一个值传递给子组件。这个值是一个 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)
我还做了这个 …
我使用sharpand webpackwithnode-loader但出现此错误:
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) 我有一个像这样的 javascript 普通对象:{a: {b: 1} }
并且我想将其转换为像这样的点符号字符串a.b = 1
用例:
将对象发送到纯文本环境(例如 cli)或作为 url 参数。
node.js ×3
angular ×2
ts-node ×2
typescript ×2
webpack ×2
angular-pipe ×1
async-pipe ×1
javascript ×1
ngx-formly ×1
node-modules ×1
observable ×1
rxjs ×1
sharp ×1
tsconfig ×1