我正在尝试从本地 Nodejs 包导入导出的成员。在使用 Vite(标准 CRA webpack 设置)之前,这些工作正常,但自从切换到 Vite 后,我收到以下错误:
Uncaught SyntaxError:
The requested module '/@fs/Users/...{long_path}.../lib/shared/countries/build/index.js'
does not provide an export named 'countryListAllIsoData'
Run Code Online (Sandbox Code Playgroud)
Vite 项目是使用npm create vite@latesttypescript 、 react、swc 预设进行设置的。
这些失败的导入仅发生在本地软件包上(没有从 npm 注册表安装的软件包),所以我确信问题出在我这边,但我无法找出导致它的原因。
由于他们确实使用 Webpack 工作,我不太确定为什么他们不能使用 Vite 工作?Vite 要求我的项目将项目设置为模块(在package.json-中"type": "module")。模块中导入的工作方式是否会破坏我当前的代码?
我正在使用 VS Code,它似乎对模块的导入方式非常满意。没有显示错误,我可以毫无问题地转到导入的定义(让我相信所有内容都已正确导出)。
我导入如下:
import { countryListAllIsoData } from "countries";
Run Code Online (Sandbox Code Playgroud)
该tsconfig.json文件未受影响(与创建时完全相同npm create vite@latest)。这同样适用于该package.json文件,除了安装了一些模块(例如导致此问题的模块)。
导致此问题的本地包已命名,countries并且相当小且简单。它有以下package.json文件:
/// package.json
{
"name": …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angular 4.1.3 版本并使用打字 1.4.0 版本。在执行 npm install 时,它会抛出以下错误。这从昨天开始就起作用了。从早上开始就出现这个问题。任何帮助,将不胜感激。
打字错误!消息无法连接到“https://api.typings.org/entries/dt/jasmine/tags/2.2.0%2B20160621224255”打字错误!证书过期导致的
打字错误!消息无法连接到“https://api.typings.org/entries/dt/core-js/tags/0.0.0%2B20160725163759”打字错误!证书过期导致的
我有 Typings.json 和以下条目
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
}
Run Code Online (Sandbox Code Playgroud)
我按照以下步骤操作,但没有成功。
我已经为 React 编写了一个 ui 包,并通过汇总包管理器来编译它们。当我发布到我的个人 bitbucket 存储库并从云安装它们时,例如:npm i https:lik-to-the-repo该包工作正常,但是当我通过绝对路径安装它时,例如;`npm i / Users / myname / Projects / Work / 项目名称”。
我用来external: [/node_modules/]让 rollup 知道我的所有包都是外部的,应该在运行时导入。
但当我使用打包包npm pack并将打包文件链接到我的存储库中时,它工作正常。'文件:../pack-dir/pack-name.tgz'
我面临这个错误
TypeError: Cannot read properties of null (reading 'useState')
at Object.useState (http://localhost:5173/node_modules/.vite/deps/chunk-ONATIWGS.js?v=e6bdb091:1066:29)
Run Code Online (Sandbox Code Playgroud)
我为 npm 安装指定的项目目录是我的 package.json 文件所在的位置。在 /Work/project-name/package.json 内部,它成功地将我的包安装在 node_modules 中,其名称在我的 package.json 中指定
在package.json中添加入口路径
"main": "dist/index.cjs",
"module": "dist/index.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"peerDependencies": {
"react": "^18.0.0",
"react-dom": ">=16.6.0"
},
Run Code Online (Sandbox Code Playgroud)
我的汇总配置
export default [
{
input: 'src/index.ts', …Run Code Online (Sandbox Code Playgroud) 我对如何在node.js模块中正确实现postgres连接池知之甚少.
我的问题是:当我在需要连接到pg的每个模块中创建新池时,它是否有问题?
有没有办法为整个应用程序全局创建池?
谢谢.
我正在使用node js和mongo db,我想将变量传递给集合
var id = "someid";
db.collection(id).insert("some json data");
Run Code Online (Sandbox Code Playgroud)
如果我这样做,将给我一个错误,因为集合名称必须是字符串。
createConnection有什么作用?
var connection = mysql.createConnection({
host : 'example.org',
user : 'bob',
password : 'secret'
});
Run Code Online (Sandbox Code Playgroud)
我正在使用mysql模块在nodeJS中编写应用程序.我有一些自己的模块,例如authentication,它们定义需要数据库连接.问题是:如果我有多个模块,我使用此方法创建连接,它是否每次都为我创建一个新连接或使用第一个?如果创建,它会在第一次加载我自己的模块时创建或每次创建?哦,如果它创造什么时候它会被摧毁?
这是我在我的authentication模块中的方式:
var config = require('./config.js');
var mysql = require('mysql');
var connection = mysql.createConnection(config.connectionString);
exports.login = function() ...
Run Code Online (Sandbox Code Playgroud)
我对模块和自己的模块如何工作有一些基本的了解.
谢谢你的回答.
当我应对并移动到具有离子3的mac时,我在我的linux任务中有了我的离子2项目.
所以我创建了一个新项目,用新项目替换了页面,提供了components文件夹,我得到了错误就像cannot find module "ionic-native"将我的插件导入app.modulte.ts文件后我得到的错误就是'类型'任何'不是构造函数功能类型
我的终端显示
17:39:48] typescript: node_modules/@ionic-native/app-version/index.d.ts, line: 25
Type 'any' is not a constructor function type. [17:39:48] typescript: node_modules/@ionic-native/geolocation/index.d.ts, line: 127 [17:39:48] typescript: node_modules/@ionic-native/google-analytics/index.d.ts, line: 30 [17:39:48] typescript: node_modules/@ionic-native/network/index.d.ts, line: 49 [17:39:48] typescript: node_modules/@ionic-native/sms/index.d.ts, line: 41 [17:39:48] typescript: node_modules/@ionic-native/social-sharing/index.d.ts, line: 29 [17:39:48] typescript: node_modules/@ionic-native/sqlite/index.d.ts, line: 115
L25: export declare class AppVersion extends IonicNativePlugin {
Type 'any' is not a constructor function type.
L127: export declare class Geolocation extends IonicNativePlugin {
Type 'any' is not a …Run Code Online (Sandbox Code Playgroud) 如果我将TypeScript模块另存为my-function.ts,如下所示:
export function myFunction (param: number): number { return param }
Run Code Online (Sandbox Code Playgroud)
它将以任何方式编译为JavaScript,并释放其类型定义。然后,我可以创建一个index.d.ts文件来声明此模块的定义,但是重新定义/重新定义这些定义似乎有点乏味。
有没有办法从my-function.ts文件自动生成类型定义到index.d.ts文件?
CopyToPublishDirectory发布dotnet应用时,我在.csproj中使用它来复制文件/文件夹:
<None Update="Views\**\*; wwwroot\**\*">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
Run Code Online (Sandbox Code Playgroud)
有没有办法复制文件夹并在此过程中更改其名称?例如,我想复制一个node_modules文件夹的子集,所以我可以创建一个名为node_modules_devnpm依赖项子集的新文件夹,然后通过CopyToPublishDirectoryas 复制它node_modules。我想语法会像这样工作:
<None Update="node_modules_dev/**/*" Rename="node_modules">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
Run Code Online (Sandbox Code Playgroud)
谢谢 -
有没有办法配置一个如此node_modules选择的WebStorm项目,library root但它也被排除在索引之外?
我发誓,我看到一个项目表明node_modules两者兼而有之library root,excluded但我无法弄清楚如何设置它.谁知道怎么样?
node-modules ×10
node.js ×7
npm ×3
angular ×2
javascript ×2
typescript ×2
.net ×1
asp.net ×1
c# ×1
csproj ×1
es6-modules ×1
ionic2 ×1
ionic3 ×1
mongodb ×1
native ×1
node-mysql ×1
pg ×1
postgresql ×1
reactjs ×1
rollupjs ×1
vite ×1
webstorm ×1