microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 128 forks source link

TypeError: Cannot redefine property: default #102

Closed phensley closed 4 years ago

phensley commented 4 years ago

Using Node 12.16.1, TypeScript 3.8.3, and tslib 1.12.0 I'm seeing this error:

/Users/phensley/dev/cldr-engine/node_modules/tslib/tslib.js:237
        Object.defineProperty(o, "default", { enumerable: true, value: v });
               ^
TypeError: Cannot redefine property: default
    at Function.defineProperty (<anonymous>)
    at /Users/phensley/dev/cldr-engine/node_modules/tslib/tslib.js:237:16
    at Object.__importStar (/Users/phensley/dev/cldr-engine/node_modules/tslib/tslib.js:246:9)
    at Object.<anonymous> (/Users/phensley/dev/cldr-engine/packages/cldr-compiler/lib/cli/compiler/index.js:4:21)

Occurs when __importStar is called: import * as yargs from 'yargs';

Transpiled to: var yargs = tslib_1.__importStar(require("yargs"));

weswigham commented 4 years ago

Ahh yeah, tslib 1.12.0 expects some emit concessions provided by TS 3.9 (namely hoisted export names) without which some stuff won't work as expected. We probably need to adjust our messaging/versioning.

Jplus2 commented 4 years ago

Encounter this as well just now, my dev env broke. It was working ok since yesterday.

when I run my start script

"start": "node build/index.js"

I see this

    Object.defineProperty(o, "default", { enumerable: true, value: v });
           ^
TypeError: Cannot redefine property: default
at Function.defineProperty (<anonymous>)

I am using

"typescript": "^3.8.2"

This is the compiled ts code to js that seemed to be where it is complaining

var __setModuleDefault = Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
};
kamilmysliwiec commented 4 years ago

Ahh yeah, tslib 1.12.0 expects some emit concessions provided by TS 3.9 (namely hoisted export names) without which some stuff won't work as expected. We probably need to adjust our messaging/versioning.

@weswigham if there's any breaking change introduced, it would be nice if a new release could be published with a major version update. This minor release broke a lot of packages that the community heavily depends on.

@DanielRosenwasser Please, consider reverting this release till the reasonable alternative is found.

bkotrys commented 4 years ago

I also noticed the same issue in my projects. Yesterday everything worked as expected, I didn't make any packages updates. Today I rebuild my docker image and I got the following error:

/app/src/index.ts:141
export {EntityManager} from "./entity-manager/EntityManager";
        ^
TypeError: Cannot set property EntityManager of #<Object> which has only a getter
    at Object.<anonymous> (/app/src/index.ts:141:9)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/app/src/commands/SchemaSyncCommand.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)

I'm pretty sure that this issue also is causing problems in typeorm package.

SkReD commented 4 years ago

Same error with yargs import as import * as args from 'yargs'

Jplus2 commented 4 years ago

I've installed tslib 1.11.2 directly as a dependency as it seems to fix the issue for me so far

"tslib": "~1.11.2"

not sure if this works for other cases tho

DanielRosenwasser commented 4 years ago

1.13.0 should fix this and be available now.

weswigham commented 4 years ago

Howdy everyone - if you're still working with TS <= 3.8, the new tslib version 1.13.0 should fix the issues you were having; it does not support live bindings, but should continue to work with both older and newer emit without a runtime error. The newly published tslib 2.0.0 has the contents of the former 1.12.0, and provides support for live bindings alongside TS 3.9+ emit; so nobody should be installing it by accident in existing projects anymore~ Sorry for the inconvenience everyone ❤️

frct1 commented 4 years ago

Hi In case of expiriencing that try to npm i -g typescript@~3.7. May be it is not a "true way" wanted way but this one can help i guess.

arunmenon1975 commented 4 years ago

Had the same issue. This comment has a temporary solution.