我正在尝试将 pouchdb 与 Typescript 一起使用。我无法链接到 pouchdb 模块。
import { PouchDB } from "pouchdb"
Run Code Online (Sandbox Code Playgroud)
报告它找不到模块 pouchdb,即使它在 node_modules 中。
我也找不到适合 pouchdb 的类型。
问题描述: 这不是这个问题的重复。我不是要访问电子模块(我使用电子包装器来执行此操作),我试图在 angular 中使用 npm 本机模块,同时在电子内部运行 angular。
原始描述:
我有一个使用电子运行的 angular 应用程序(一个新应用程序,还没有做任何事情)。要访问蓝牙,我使用了noble和bleno,但是当它们在 Electron 中工作时(为了测试我添加noble = require('noble')到电子文件夹中的 index.js),当我将例如 noble 添加到 app.compoents.js 中时,它们不起作用棱角分明。
这是我的 app.component.ts
import { Component } from '@angular/core';
import {ElectronService} from 'ngx-electron';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title: String = 'Colaboration room';
noble = require('noble')
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
./node_modules/bindings/bindings.js 76:43-53 中的警告 关键依赖:依赖的请求是一个表达式
虽然这只是一个警告,但 angular 初始页面不再显示(它是空的)。
问题: 如何在 Angular 中访问节点本机模块(在电子中运行时)?
附加信息:
我使用 angulars 默认编译器webpack …
我有一个库,我想在发布到 npm 之前在本地进行完整安装来测试它。我想测试的一件事是所有依赖项是否都是项目的一部分。由于nodejs如何构建其模块系统,(在每个目录级别搜索nodejs模块)我没有一个好的方法来确保我需要的模块来自当前文件夹的node_modules,而不是父文件夹的node_modules 。
这是项目结构:
library-folder/
package.json
node_modules/
testing/integration/
package.json
node_modules/
test-install.js
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以告诉nodejs只需要当前目录中的模块,并忽略任何父目录。
我不知道为什么会这样显示,问题发生在 Bundler.js 上,错误指向这一行。
TransformFile(filePath, transformOptions) {
var _this3 = this;
return _asyncToGenerator(function*() {
// We need to be sure that the DependencyGraph has been initialized.
// TODO: Remove this ugly hack!
yield _this3._depGraphPromise;
return _this3._transformer.transformFile(filePath, transformOptions);
})();
Run Code Online (Sandbox Code Playgroud)
补充一点可能很重要,我是通过 nvm 安装节点的。
谢谢你!
我\xe2\x80\x99 的任务是在工作中对我们的 Node 应用程序进行 docker 化。当谈到node_modules时,我与我们的首席开发人员有点分歧。
\n他在 dockerfile 中提倡类似的东西。他的理由是 docker 镜像将更具确定性,在这一点上我不\xe2\x80\x99t 完全不同意他的观点。
\nCOPY node_modules ./\nRun Code Online (Sandbox Code Playgroud)\n我提倡这样的事情。我的推理.. \xe2\x80\x99 本质上是互联网上每个人都说的做法,包括Node 文档和Docker 文档。我希望我是从技术角度争论的,但我似乎只能\xe2\x80\x99t 找到任何专门解决这个问题的东西。
\nCOPY package*.json ./\nRUN npm install\nRun Code Online (Sandbox Code Playgroud)\n那么谁是对的呢?第一种选择有哪些缺点?
\n我有一个自定义节点模块,已添加到我的 React 项目中。当我从模块导入组件并运行应用程序时,它返回错误:
Compiled with problems:
ERROR in ./node_modules/react-quick-reactions/src/components/QuickReactions.tsx 4:29
Module parse failed: Unexpected token (4:29)
File was processed with these loaders:
* ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| import { PopoverProps } from "../types/types";
|
> const QuickReactions = (props: PopoverProps) => {
| const {
| isVisible = false,
Run Code Online (Sandbox Code Playgroud)
我试图找到类似的问题,但其他人遇到了无效合并运算符的问题,这些运算符不在问题行上,更不用说在文件中使用了。模块的文件:
import { useMemo, useState } from "react";
import { PopoverProps } from "../types/types";
const QuickReactions = (props: PopoverProps) => …Run Code Online (Sandbox Code Playgroud) 当写入“npm start”时,我收到一些错误消息“找不到模块..\acorn.js”
包.json
{
"name": "eats-mate-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"acorn": "^8.8.0",
"axios": "^0.27.2",
"bootstrap": "^5.1.3",
"react": "^18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
"react-kakao-maps-sdk": "^1.1.1",
"react-persist": "^1.0.2",
"react-redux": "^8.0.2",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"redux-persist": "^6.0.0",
"redux-promise": "^0.6.0",
"redux-thunk": "^2.4.1",
"save": "^2.5.0",
"slick-carousel": "^1.8.1",
"source-map": "^0.7.4",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [ …Run Code Online (Sandbox Code Playgroud) NodeJS:v18.7.0
\nNPM:8.15.0
\nrollup.config.js:
import typescript from '@rollup/plugin-typescript';\nimport dts from 'rollup-plugin-dts';\n\nimport tsConfig from './tsconfig.json';\n\nconst config = [\n {\n input: "index.ts",\n output: [{ file: "build/index.js", sourcemap: true }],\n plugins: [\n typescript(\n {\n sourceMap: tsConfig.compilerOptions.sourceMap\n }\n )\n ]\n },\n {\n input: 'build/index.d.ts',\n output: [{ file: "build/index.d.ts", "format": "es" }],\n plugins: [\n dts(\n {\n compilerOptions: {\n baseUrl: tsConfig.compilerOptions.baseUrl\n }\n }\n )\n ]\n },\n]\n\nexport default config;\nRun Code Online (Sandbox Code Playgroud)\ntsconfig.json:
{\n "compilerOptions": {\n "plugins": [\n {\n "name": "@rollup/plugin-typescript"\n }\n ]\n }\n}\n …Run Code Online (Sandbox Code Playgroud) 我们有一个每天晚上都会构建的代码库。昨晚,它无法构建(我没有进行与 NPM 库相关的更改)。
我收到以下错误:
ERROR TS2688: Cannot find type definition file for 'keyv'.
The file is in the program because: Entry point for implicit type library 'keyv'.
Run Code Online (Sandbox Code Playgroud)
我发现 keyv 库不在我的包 json 中,但 package.json 中列出的其他一些包正在使用它。在 package-lock.json 中,我发现 @types/keyv 在多个地方使用。
搜索类型库并查看 package-lock.json 中的更改会导致这一行,这是其链接:
https://www.npmjs.com/package/@types/keyv “这是一个存根类型定义。keyv 提供了自己的类型定义,因此您不需要安装它。”
使用“keyv”的软件包尝试使用已弃用的@types/keyv。
在本地主机上运行“npm start”后,出现以下错误:
./node_modules/chart.js/dist/chart.js 695:18 模块解析失败:意外的标记 (695:18) 文件已使用这些加载器处理:
静态默认值= {};| 静态数据集元素类型 = null; | 静态数据元素类型 = null;
我已经更新了 Chart.js 和 React Chartjs 2 的版本。我删除了 node_modules 和 package-lock.json 并重新安装,应用程序未启动。我已经删除了node_modules/package-lock.json/clear npm 缓存。没有帮助。
node-modules ×10
node.js ×6
typescript ×4
reactjs ×3
angular ×1
bundler ×1
chart.js ×1
couchdb ×1
dependencies ×1
docker ×1
dockerfile ×1
electron ×1
npm ×1
package.json ×1
plugins ×1
pouchdb ×1
react-native ×1
rollupjs ×1
tsconfig ×1
types ×1