Skip to content
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

TypeError: Cannot redefine property: default #38679

Closed
zhinanchendd01 opened this issue May 20, 2020 · 11 comments
Closed

TypeError: Cannot redefine property: default #38679

zhinanchendd01 opened this issue May 20, 2020 · 11 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status. Needs More Info The issue still hasn't been fully clarified

Comments

@zhinanchendd01
Copy link

zhinanchendd01 commented May 20, 2020

TypeScript Version: 3.9.3

Code

file1.js

module.exports = {
  default: {
    log() {
    }
  },
}

file2.ts

import file1 from './file1'
file1.log()

Actual behavior:

TypeError: Cannot redefine property: default

Related Issues: #38552

@zhinanchendd01 zhinanchendd01 changed the title Cannot redefine property: default TypeError: Cannot redefine property: default May 22, 2020
@joeldenning
Copy link

This is likely a duplicate of #38540

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone May 26, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 26, 2020
@weswigham
Copy link
Member

I actually can't reproduce the issue in the OP - @zhinanchendd01 is there more context to this? Or a specific set of compiler options? I've tried both with and without esModuleInterop on, and can't replicate your result.

@weswigham weswigham added the Needs More Info The issue still hasn't been fully clarified label May 27, 2020
@malord
Copy link

malord commented May 31, 2020

I just had this with TypeScript 3.9.3. This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "outDir": "./lib",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true
  },
  "exclude": [
    "test"
  ]
}

I found out that this fails:

import sequelize, { Op, Sequelize } from 'sequelize';

But this works:

import { Op, Sequelize } from 'sequelize';  
import sequelize from 'sequelize';

@Johnvict
Copy link

I just had this with TypeScript 3.9.3. This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "outDir": "./lib",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true
  },
  "exclude": [
    "test"
  ]
}

I found out that this fails:

import sequelize, { Op, Sequelize } from 'sequelize';

But this works:

import { Op, Sequelize } from 'sequelize';  
import sequelize from 'sequelize';

This solved the whole thing.. Thank you

@aecorredor
Copy link

Same exact thing is happening to me with sequelize right after going from 3.8.3 to 3.9.3. Is this expected or is it a regression?

@aecorredor
Copy link

Just saw there's a fix already in #38540

@zhinanchendd01
Copy link
Author

my tsconfig.json

{
	"compileOnSave": true,
	"compilerOptions": {
		"target": "es2018",
		"module": "commonjs",
		"esModuleInterop": true,
		"outDir": "dist",
		"baseUrl": "src",
	},
	"exclude": ["dist", "node_modules"]
}

logger.js

const info = (...args) => {
  console.log(...args)
}

const debug = (...args) => {
  console.debug(...args)
}

module.exports = { info, debug }

module.exports.default = { info, debug }

index.ts

this failed:

import * as logger from './logger'
logger.debug('debug 1')
// TypeError: Cannot redefine property: default

this can work:

import logger from './logger'
logger.debug('debug 1')

@weswigham

@zhinanchendd01
Copy link
Author

logger.js

const info = (...args) => {
  console.log(...args)
}

const debug = (...args) => {
  console.debug(...args)
}

module.exports.default = { info, debug }

index.ts

import logger from './logger'
logger.info('info')
// TypeError: logger_1.default.info is not a function

console.log(logger)
// { default: { info: [Function: info], debug: [Function: debug] } }

SamuelMarks added a commit to SamuelMarks/orm-mw that referenced this issue Jun 3, 2020
microsoft/TypeScript#38679 to resolve 'TypeError: Cannot redefine property: default'; [package.json,package-lock.json] Bump version
@kherock
Copy link

kherock commented Jun 4, 2020

This actually appears to be fixed for my code in v3.9.4, but it's not currently published to npm with the latest tag.

@MaciekBaron
Copy link

MaciekBaron commented Jun 5, 2020

But this works:

import { Op, Sequelize } from 'sequelize';  
import sequelize from 'sequelize';

I have exactly the same issue – for some reason I cannot write:

import parse, { domToReact } from 'html-react-parser';

I have to split it into two lines.

EDIT: Seems to be fixed when using [email protected]

@alansoliditydev
Copy link

This helps me.

    "typescript": "3.9.7",
    "tslib": "1.13.0"

offtherailz added a commit to offtherailz/MapStore2 that referenced this issue Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status. Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

10 participants