如何通过 npm 运行 独立制作 angular component.ts 脚本 运行?
How to make the angular component.ts script run independently via npm run?
我有一个 addDataComponent
用于向数据库添加数据。出于开发目的,我希望能够在应用程序之外 运行 这个 ts/component 脚本。这是我尝试过的:
npx ts-node addDataComponent.ts
,但是没有成功,错误显示:
(node:36051) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Cannot use import statement outside a module
- 在
packages.json
和运行node --loader ts-node/esm addDataComponent.ts
中添加"type": "module"
,但也没用:
(node:50489) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/app/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:376
const err = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base));
^
Error: ERR_UNSUPPORTED_DIR_IMPORT /Users/app/src /Users/app/
抱歉,我没有可重现的示例,但我在组件中的格式是:
addDataComponent.html
addDataComponent.ts
addDataComponent.module.ts
我是 angular/typescript 的新手,我不知道如何解决模块问题。 运行独立一个组件最好的是什么?
谢谢!
意思是运行绑定这个组件,如果你的意思是你想在里面运行一个函数,那么你可以把这个函数写成服务,随时随地调用它。
我有一个 addDataComponent
用于向数据库添加数据。出于开发目的,我希望能够在应用程序之外 运行 这个 ts/component 脚本。这是我尝试过的:
npx ts-node addDataComponent.ts
,但是没有成功,错误显示:
(node:36051) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Cannot use import statement outside a module
- 在
packages.json
和运行node --loader ts-node/esm addDataComponent.ts
中添加"type": "module"
,但也没用:
(node:50489) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/app/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:376
const err = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base));
^
Error: ERR_UNSUPPORTED_DIR_IMPORT /Users/app/src /Users/app/
抱歉,我没有可重现的示例,但我在组件中的格式是:
addDataComponent.html
addDataComponent.ts
addDataComponent.module.ts
我是 angular/typescript 的新手,我不知道如何解决模块问题。 运行独立一个组件最好的是什么?
谢谢!
意思是运行绑定这个组件,如果你的意思是你想在里面运行一个函数,那么你可以把这个函数写成服务,随时随地调用它。