简体   繁体   English

TypeError: undefined is not an object (评估 '_$$_REQUIRE(_dependencyMap[4], "./index").applyMiddleware.apply')

[英]TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[4], "./index").applyMiddleware.apply')

I am creating a news application using react-native typescript.我正在使用react-native typescript 创建一个新闻应用程序。 I want to use redux persist to store the state of application.我想使用redux persist 来存储应用程序的状态。 If the application is being opened for first time I want to display the login page else I want to store the state of application.如果应用程序是第一次打开,我想显示登录页面,否则我想存储应用程序的状态。 But when i start the application it throws me error as "UNDEFINED IS NOT AN OBJECT".但是当我启动应用程序时,它会向我抛出错误,因为“未定义不是对象”。 and two more errors as "AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native."还有两个错误,“AppRegistry 不是注册的可调用模块(调用 runApplication)。错误的常见原因是应用程序入口文件路径不正确。当 JS 包损坏或早期初始化时也会发生这种情况加载 React Native 时出错。”

this is how my app.tsx looks file:这就是我的app.tsx文件的外观:

import React, {FC} from 'react';
import {Provider} from 'react-redux';
import {persistStore} from 'redux-persist';
import {PersistGate} from 'redux-persist/integration/react';
import reduxStore from './src/redux';

import RootNavigation from '@navigation/index';

interface IProps {}

/**
 * @author Nitesh Raj Khanal
 * @function @App
 **/

export const reduxPersistStore = persistStore(reduxStore);

const App: FC<IProps> = () => {
  return (
    <Provider store={reduxStore}>
      <PersistGate persistor={persistStore(reduxStore)}>
        <RootNavigation />
      </PersistGate>
    </Provider>
  );
};

export default App;

this is how my store looks like:这就是我的商店的样子:

import {
  legacy_createStore as createStore,
  compose,
  applyMiddleware,
} from 'redux';
import thunk from 'redux-thunk';

import rootReducer from '@reducers/index';
import promiseMiddleware from './middleware/ApiCall';

let middleware = [thunk, promiseMiddleware];

const reduxStore = createStore(
  rootReducer,
  compose(applyMiddleware(...middleware)),
);

export default reduxStore;

this is my root reducer:这是我的根减速器:

import {persistReducer} from 'redux-persist';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Constants from '@constants/index';
import authReducer from './authReducers';

const config = {
  key: Constants.asyncStorageKey,
  storage: AsyncStorage,
  blacklist: [],
};

const appReducer = persistReducer(config, {
  auth: authReducer,
});

const rootReducer = (state: any, action: any) => {
  return appReducer(state, action);
};

export default rootReducer;

this is the promise middleware:这是承诺中间件:

const promiseMiddleware = () => {
  return next => action => {
    const {promise, type, ...rest} = action;

    if (!promise) return next(action);

    const SUCCESS = type + '_SUCCESS';
    const REQUEST = type + '_REQUEST';
    const FAILURE = type + '_FAILURE';

    next({...rest, type: REQUEST});

    return promise
      .then(response => {
        next({...rest, response: response, type: SUCCESS});
        return true;
      })
      .catch(error => {
        next({...rest, error: error, type: FAILURE});
        return false;
      });
  };
};

export default promiseMiddleware;

this is my package.json file这是我的 package.json 文件

{
  "name": "newsamnil",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.17.5",
    "@react-navigation/bottom-tabs": "^6.3.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/stack": "^6.2.1",
    "axios": "^0.27.2",
    "formik": "^2.2.9",
    "moment": "^2.29.3",
    "react": "17.0.2",
    "react-native": "0.68.2",
    "react-native-app-intro-slider": "^4.0.4",
    "react-native-extended-stylesheet": "^0.12.0",
    "react-native-gesture-handler": "^2.4.2",
    "react-native-modal": "^13.0.1",
    "react-native-render-html": "^6.3.4",
    "react-native-safe-area-context": "^4.2.5",
    "react-native-screens": "^3.13.1",
    "react-native-simple-toast": "^1.1.3",
    "react-native-size-matters": "^0.4.0",
    "react-native-snackbar": "^2.4.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-redux": "^8.0.1",
    "redux": "^4.2.0",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.4.1",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.67.3",
    "@types/react-native-vector-icons": "^6.4.10",
    "@types/react-test-renderer": "^17.0.1",
    "@typescript-eslint/eslint-plugin": "^5.17.0",
    "@typescript-eslint/parser": "^5.17.0",
    "babel-jest": "^26.6.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-native-vector-icons": "^9.1.0",
    "react-test-renderer": "17.0.2",
    "typescript": "^4.4.4"
  },
  "resolutions": {
    "@types/react": "^17"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}

this is tsconfig.json这是 tsconfig.json

// prettier-ignore
{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Projects */
    // "incremental": true,                              /* Enable incremental compilation */
    // "composite": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */
    // "tsBuildInfoFile": "./",                          /* Specify the folder for .tsbuildinfo incremental compilation files. */
    // "disableSourceOfProjectReferenceRedirect": true,  /* Disable preferring source files instead of declaration files when referencing composite projects */
    // "disableSolutionSearching": true,                 /* Opt a project out of multi-project reference checking when editing. */
    // "disableReferencedProjectLoad": true,             /* Reduce the number of projects loaded automatically by TypeScript. */

    /* Language and Environment */
    "target": "esnext",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "lib": ["es2017"],                                   /* Specify a set of bundled library declaration files that describe the target runtime environment. */
    "jsx": "react-native",                               /* Specify what JSX code is generated. */
    // "experimentalDecorators": true,                   /* Enable experimental support for TC39 stage 2 draft decorators. */
    // "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */
    // "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
    // "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
    // "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
    // "reactNamespace": "",                             /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
    // "noLib": true,                                    /* Disable including any library files, including the default lib.d.ts. */
    // "useDefineForClassFields": true,                  /* Emit ECMAScript-standard-compliant class fields. */

    /* Modules */
    "module": "commonjs",                                /* Specify what module code is generated. */
    // "rootDir": "./",                                  /* Specify the root folder within your source files. */
    "moduleResolution": "node",                          /* Specify how TypeScript looks up a file from a given module specifier. */
    "baseUrl": "./",                                  /* Specify the base directory to resolve non-relative module names. */
    "paths":{
      "@components/*":["src/components/*"],
      "@api/*":["src/api/*"],
      "@assets/*":["src/assets/*"],
      "@constants/*":["src/constants/*"],
      "@navigation/*":["src/navigation/*"],
      "@actions/*":["src/redux/actions/*"],
      "@reducers/*":["src/redux/reducers/*"],
      "@screens/*":["src/screens/*"],
    },                                     /* Specify a set of entries that re-map imports to additional lookup locations. */
    // "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */
    // "typeRoots": [],                                  /* Specify multiple folders that act like `./node_modules/@types`. */
    // "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */
    // "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */
    "resolveJsonModule": true,                           /* Enable importing .json files */
    // "noResolve": true,                                /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */

    

    /* JavaScript Support */
    "allowJs": true,                                     /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
    // "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */
    // "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */

    /* Emit */
    // "declaration": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
    // "declarationMap": true,                           /* Create sourcemaps for d.ts files. */
    // "emitDeclarationOnly": true,                      /* Only output d.ts files and not JavaScript files. */
    // "sourceMap": true,                                /* Create source map files for emitted JavaScript files. */
    // "outFile": "./",                                  /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
    // "outDir": "./",                                   /* Specify an output folder for all emitted files. */
    // "removeComments": true,                           /* Disable emitting comments. */
    "noEmit": true,                                      /* Disable emitting files from a compilation. */
    // "importHelpers": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
    // "importsNotUsedAsValues": "remove",               /* Specify emit/checking behavior for imports that are only used for types */
    // "downlevelIteration": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
    // "sourceRoot": "",                                 /* Specify the root path for debuggers to find the reference source code. */
    // "mapRoot": "",                                    /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */
    // "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */
    // "emitBOM": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
    // "newLine": "crlf",                                /* Set the newline character for emitting files. */
    // "stripInternal": true,                            /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
    // "noEmitHelpers": true,                            /* Disable generating custom helper functions like `__extends` in compiled output. */
    // "noEmitOnError": true,                            /* Disable emitting files if any type checking errors are reported. */
    // "preserveConstEnums": true,                       /* Disable erasing `const enum` declarations in generated code. */
    // "declarationDir": "./",                           /* Specify the output directory for generated declaration files. */
    // "preserveValueImports": true,                     /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

    /* Interop Constraints */
    "isolatedModules": true,                             /* Ensure that each file can be safely transpiled without relying on other imports. */
    "allowSyntheticDefaultImports": true,                /* Allow 'import x from y' when a module doesn't have a default export. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */

    /* Type Checking */
    "strict": true,                                      /* Enable all strict type-checking options. */
    // "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied `any` type.. */
    // "strictNullChecks": true,                         /* When type checking, take into account `null` and `undefined`. */
    // "strictFunctionTypes": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
    // "strictBindCallApply": true,                      /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
    // "strictPropertyInitialization": true,             /* Check for class properties that are declared but not set in the constructor. */
    // "noImplicitThis": true,                           /* Enable error reporting when `this` is given the type `any`. */
    // "useUnknownInCatchVariables": true,               /* Type catch clause variables as 'unknown' instead of 'any'. */
    // "alwaysStrict": true,                             /* Ensure 'use strict' is always emitted. */
    // "noUnusedLocals": true,                           /* Enable error reporting when a local variables aren't read. */
    // "noUnusedParameters": true,                       /* Raise an error when a function parameter isn't read */
    // "exactOptionalPropertyTypes": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */
    // "noImplicitReturns": true,                        /* Enable error reporting for codepaths that do not explicitly return in a function. */
    // "noFallthroughCasesInSwitch": true,               /* Enable error reporting for fallthrough cases in switch statements. */
    // "noUncheckedIndexedAccess": true,                 /* Include 'undefined' in index signature results */
    // "noImplicitOverride": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */
    // "noPropertyAccessFromIndexSignature": true,       /* Enforces using indexed accessors for keys declared using an indexed type */
    // "allowUnusedLabels": true,                        /* Disable error reporting for unused labels. */
    // "allowUnreachableCode": true,                     /* Disable error reporting for unreachable code. */

    /* Completeness */
    // "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  },
  "exclude": [
    "node_modules", "babel.config.js", "metro.config.js", "jest.config.js"
  ]
}

this is babel.config.js file这是 babel.config.js 文件

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        cwd: 'babelrc',
        extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.svg'],
        root: ['./src'],
        alias: {
          '@components': './src/components',
          '@api': './src/api',
          '@assets': './src/assets',
          '@constants': './src/constants',
          '@navigation': './src/navigation',
          '@actions': './src/redux/actions',
          '@reducers': './src/redux/reducers',
          '@screens': './src/screens',
        },
      },
    ],
  ],
};

Please rename your folder src/redux to something else, maybe src/store .请将您的文件夹src/redux重命名为其他名称,可能是src/store That often tends to solve issues like this.这通常倾向于解决这样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:“未定义”不是对象(评估) - TypeError: ‘undefined’ is not an object (evaluating) TypeError: undefined is not an object(评估“this”) - TypeError: undefined is not an object (evaluating 'this') TypeError: undefined is not an object(评估 XYZ) - TypeError: undefined is not an object (evaluating XYZ) "TypeError: (0, _$$_REQUIRE(_dependencyMap[0], &quot;redux&quot;).createStore) 不是函数 react-native" - TypeError: (0, _$$_REQUIRE(_dependencyMap[0], "redux").createStore) is not a function react-native TypeError: undefined is not an object(评估'object ['body']') - TypeError: undefined is not an object (evaluating 'object['body']') React Native - TypeError:undefined 不是评估 _useContext 的对象 - React native - TypeError: undefined is not an object evaluating _useContext TypeError:未定义不是对象(评估this.getActiveTab()。barColor) - TypeError: undefined is not an object (evaluating this.getActiveTab().barColor) 类型错误:未定义不是对象(评估“_useContext.user”) - TypeError: undefined is not an object (evaluating '_useContext.user') TypeError: undefined is not an object(评估'_this.showActionSheet') - TypeError: undefined is not an object (evaluating '_this.showActionSheet') TypeError: undefined is not an object(评估'_this.setState') - TypeError: undefined is not an object (evaluating ' _this.setState')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM