gpt4 book ai didi

typescript - 如何修复未声明的 "error: bundling failed: SyntaxError: { path }\PinCode\index.ts: Exporting local "IPinCodeParams"。"在 React-Native 中?

转载 作者:行者123 更新时间:2023-12-03 08:01:56 27 4
gpt4 key购买 nike

我创建了一个新项目。我有接口(interface),类型等的特殊文件夹。我会有很多,所以我将它们导入一个文件并从那里导出它们。当我想导出多个接口(interface)时出现错误:

error: bundling failed: SyntaxError: C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\react-native\scripts\src\types\PinCode\index.ts: Exporting local "IPinCodeParams", which is not declared.
13 | }
14 |
> 15 | export { PinStatus, IPinCodeParams }
| ^
at File.buildCodeFrameError (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\core\lib\transformation\file\file.js:261:12)
at NodePath.buildCodeFrameError (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\traverse\lib\path\index.js:157:21)
at getLocalMetadata (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\helper-module-transforms\lib\normalize-and-load-metadata.js:281:22)
at child.get.forEach.spec (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\helper-module-transforms\lib\normalize-and-load-metadata.js:315:11)
at Array.forEach (<anonymous>)
at programPath.get.forEach.child (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\helper-module-transforms\lib\normalize-and-load-metadata.js:307:33)
at Array.forEach (<anonymous>)
at getLocalExportMetadata (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\helper-module-transforms\lib\normalize-and-load-metadata.js:294:27)
at getModuleMetadata (C:\Users\QWERTY\Desktop\TestProjects\2019\TestProject\node_modules\@babel\helper-module-transforms\lib\normalize-and-load-metadata.js:86:21)

我有这个文件夹结构:
android\
ios\
node_modules\
src\
--->constants\
|--->colors.ts
|--->fonts.ts
|--->index.ts
--->router\
|--->index.ts
--->screen\
|--->Splash\
|--->containers\
|--->index.ts
|--->SplashContainer.tsx
|--->views\
|--->index.ts
|--->SplashView.tsx
|--->index.tsx
|--->index.ts
--->types\
|--->PinCode\
|--->index.tsx
|--->index.tsx
--->App.tsx
.babelrc
*
*
*
package.json
rn-cli.config.js
tsconfig.json
tslint.json

在文件 “密码”我有一个枚举和一个接口(interface)。

当我这样写时(好吧):
export enum PinStatus {
New = 'new',
Confirm = 'confirm',
Unlock = 'unlock',
Edit = 'edit',
}

export interface IPinCodeParams {
status: PinStatus;
onComplete: () => void;
onClose?: () => void;
originalCode?: string;
}

但是当我这样写时(我得到错误):
enum PinStatus {
New = 'new',
Confirm = 'confirm',
Unlock = 'unlock',
Edit = 'edit',
}

interface IPinCodeParams {
status: PinStatus;
onComplete: () => void;
onClose?: () => void;
originalCode?: string;
}

export { PinStatus, IPinCodeParams };

我创建了一些全新的项目,尝试多次重写这个项目,但没有任何结果。无论如何,我终于得到了这个错误。

包.json
{
"name": "TestProject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "node node_modules/react-native/local-cli/cli.js run-android",
"ios": "node node_modules/react-native/local-cli/cli.js run-ios",
"lint": "yarn tslint && yarn typecheck",
"tslint": "tslint --project tsconfig.json --config tslint.json src/**/*.ts{,x} --format stylish",
"typecheck": "tsc --project tsconfig.json --noEmit",
"postinstall": "typesync",
"type-sync": "typesync"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint",
"pre-push": "yarn lint"
}
},
"dependencies": {
"mobx": "^4.9.2",
"mobx-persist": "^0.4.1",
"mobx-react": "^5.4.3",
"react": "16.8.0",
"react-native": "0.58.4",
"react-native-vector-icons": "^6.2.0",
"react-navigation": "^2.18.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/plugin-proposal-decorators": "^7.3.0",
"@types/babel-core": "6.25.5",
"@types/jest": "24.0.0",
"@types/prettier": "^1.16.0",
"@types/react": "16.8.2",
"@types/react-native": "0.57.34",
"@types/react-native-vector-icons": "^4.6.4",
"@types/react-navigation": "^3.0.1",
"@types/react-test-renderer": "16.8.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "24.1.0",
"babel-plugin-module-resolver": "^3.1.3",
"husky": "^1.3.1",
"jest": "24.1.0",
"jsc-android": "236355.1.1",
"metro-react-native-babel-preset": "0.51.1",
"mobx-logger": "^0.7.1",
"prettier": "^1.16.4",
"react-native-typescript-transformer": "^1.2.11",
"react-test-renderer": "16.6.3",
"tslint": "^5.12.1",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^3.6.0",
"typescript": "^3.2.4",
"typesync": "^0.4.1"
},
"jest": {
"preset": "react-native"
}
}

.babelrc
{
"presets": [
"module:metro-react-native-babel-preset",
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/transform-react-jsx-source",
[
"module-resolver",
{
"root": [
"/src"
],
"alias": {
"@api": "./src/api",
"@actions": "./src/actions",
"@components": "./src/components",
"@constants": "./src/constants",
"@hocs": "./src/hocs",
"@managers": "./src/managers",
"@locales": "./src/locales",
"@reducers": "./src/reducers",
"@screens": "./src/screens",
"@static": "./src/static",
"@stores": "./src/stores",
"@styles": "./src/styles",
"@types": "./src/types",
"@utils": "./src/utils"
}
}
],
]
}

tsconfing.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"jsx": "react-native",
"baseUrl": "./src",
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmit": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"paths": {
"@api": [
"api"
],
"@actions": [
"actions"
],
"@components": [
"components"
],
"@constants": [
"constants"
],
"@hocs": [
"hocs"
],
"@managers": [
"managers"
],
"@locales": [
"locales"
],
"@reducers": [
"reducers"
],
"@screens": [
"screens"
],
"@static": [
"static"
],
"@stores": [
"stores"
],
"@styles": [
"styles"
],
"@types": [
"types"
],
"@utils": [
"utils"
]
}
},
}

tslist.json
{
"defaultSeverity": "error",
"extends": [
"tslint-config-prettier",
"tslint-eslint-rules",
"tslint-react",
"tslint:latest"
],
"jsRules": {},
"rules": {
"await-promise": false,
"interface-over-type-literal": false,
"jsx-alignment": true,
"jsx-boolean-value": false,
"jsx-no-bind": true,
"jsx-no-lambda": false,
"max-classes-per-file": false,
"member-access": false,
"member-ordering": false,
"no-constant-condition": false,
"no-duplicate-imports": false,
"no-empty": false,
"no-implicit-dependencies": false,
"no-submodule-imports": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [
true,
"single",
"jsx-single",
"avoid-escape"
],
"semicolon": [
true,
"always"
],
"trailing-comma": [
true,
{
"singleline": "never",
"multiline": "always"
}
],
"triple-equals": [
true,
"allow-undefined-check"
]
},
"linterOptions": {
"exclude": [
"./src/typings/**/*.d.ts"
]
},
"rulesDirectory": []
}

Reference to the source project (Github)

为什么我会收到此错误?如何解决?

最佳答案

实际上,您在自己的问题中写下答案:

export enum PinStatus {
New = 'new',
Confirm = 'confirm',
Unlock = 'unlock',
Edit = 'edit',
}

export interface IPinCodeParams {
status: PinStatus;
onComplete: () => void;
onClose?: () => void;
originalCode?: string;
}

关于typescript - 如何修复未声明的 "error: bundling failed: SyntaxError: { path }\PinCode\index.ts: Exporting local "IPinCodeParams"。"在 React-Native 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54594443/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com