Is there a difference in module creation if I use export * instead of export {Component1,...

Discussão em 'Angular' iniciado por IMeyers20, Dezembro 6, 2024.

  1. IMeyers20

    IMeyers20 Guest

    I recently ran into a failing test where I received the following error message"

    TypeError: Cannot redefine property: getCurrentRouteSnapshot


    I read the following StackOverflow and found this could be a result of __esModule being false, leading to the import not being configurable. jest spyOn not working on index file, cannot redefine property.

    While the solution there worked, it felt like a bit of a bandaid fix, and I was curious why __esModule was false in the first place.

    My index file that exports that helper function contains the following:

    export * from './router.tools';


    I looked into my tsconfig.spec.json, which looks like the following:

    {
    "extends": "./tsconfig.json",
    "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "CommonJS",
    "target": "ES2016",
    "types": ["jest", "node", "chart.js"],
    "allowJs": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
    },
    "include": ["src/**/*.spec.ts", "../../types/**/*"]
    }


    I noticed that "module" was set to "CommonJS".

    When I was looking into CommonJS export standards, I wasn't seeing anywhere that would use export *.

    How export all variable on commonjs from deferent file in one place

    I changed my index.ts to instead export the following (All exports individually):

    export {getCurrentRouteSnapshot, GetCurrentApplication, routeToProbeFeature, ApplicationType, MonitorableTab} from './router.tools';


    This fixed the failing test.

    Why would export * lead to this not being configurable, but export {/*All Modules*/} does not?

    Continue reading...

Compartilhe esta Página