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

WIP: fix: restore default export #705

Closed
wants to merge 1 commit into from
Closed

WIP: fix: restore default export #705

wants to merge 1 commit into from

Conversation

pawel-id
Copy link
Contributor

@pawel-id pawel-id commented Oct 5, 2023

Explain your changes


It seems typescript clause export default someting is translated into exports.default = sgd; which is somehow different that expected module.exports = sgd. Then having this approach in order to import this we need to do some extra work:

const sgd = require('module').default

or

import sgdDefault from 'module'
const sgd = sgdDefault.default

This is some proposal of solving the issue which I found. It is rather provided as example, not necessarily to merge (maybe there is smarter way).

related to #701

@codeclimate
Copy link

codeclimate bot commented Oct 5, 2023

Code Climate has analyzed commit 32e7a4e and detected 0 issues on this pull request.

View more on Code Climate.

@pawel-id pawel-id changed the title fix: restore default export WIP: fix: restore default export Oct 5, 2023
@pawel-id pawel-id closed this Oct 5, 2023
Copy link
Owner

@scolladon scolladon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this solution

I think it could work if we do

export = sgd

instead of

export default sgd

line 30 in main.ts

Then we won't need to have the index.cjs file
What do you think @pawel-id, could you test it on your side ?

@@ -1,5 +1,5 @@
{
"extends": "./node_modules/@salesforce/dev-config/tsconfig",
"extends": "./node_modules/@salesforce/dev-config/tsconfig.json",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why should we add the extension here?

Is it solving something ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig.json change shouldn't be there. Please ignore it.

checking the solution with export = sgd...

Comment on lines +1 to +2
const sgd = require('./main.js').default
module.exports = sgd
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praises: Smart way to workaround

@pawel-id
Copy link
Contributor Author

pawel-id commented Oct 5, 2023

Thanks for this solution

I think it could work if we do

export = sgd

instead of

export default sgd

line 30 in main.ts

Then we won't need to have the index.cjs file What do you think @pawel-id, could you test it on your side ?

@scolladon This works and it is super simple!

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

Successfully merging this pull request may close these issues.

2 participants