Skip to content

TypeError: Cannot redefine property: default #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phensley opened this issue May 12, 2020 · 10 comments
Closed

TypeError: Cannot redefine property: default #102

phensley opened this issue May 12, 2020 · 10 comments

Comments

@phensley
Copy link

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
Copy link
Member

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
Copy link

Jplus2 commented May 13, 2020

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
Copy link

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
Copy link

bkotrys commented May 13, 2020

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
Copy link

SkReD commented May 13, 2020

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

@Jplus2
Copy link

Jplus2 commented May 13, 2020

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
Copy link
Member

1.13.0 should fix this and be available now.

@weswigham
Copy link
Member

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
Copy link

frct1 commented May 30, 2020

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants