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

chore(internal): fix dendron-plugin-views build #3775

Merged
merged 4 commits into from
Nov 11, 2022

Conversation

namjul
Copy link
Contributor

@namjul namjul commented Nov 10, 2022

This aim of this PR is to fix the build task within dendron-plugin-views package which currently results into the following error:

/home/nam/code/dendronhq/dendron/node_modules/zod-validation-error/node_modules/@swc/helpers/src/index.mjs
Can't reexport the named export '__decorate' from non EcmaScript module (only default export is available)

The commit 419dec7 (PR: #3762) is responsible for this by adding a dependency
which conflicts with the webpack build in dendron-plugin-views. That
dependency uses withing its cjs build files @swc/helpers which
conflicts with the import type from webpack.
@swc/helpers provides a module entry https://github.com/swc-project/swc/blob/main/packages/swc-helpers/package.json#L6-L7 which has named reexports which gets flagged as an error.

Update: Found a solution which works by pinning zod-validation-error to an other version: 5e406cc


Update: I tried another solution to tell webpack to prefer main entry field instead of `module´. But since that would disable webpacks tree-shaking capabilities since this requries static module structure I reverted that change.


The solution is to use explicitly set Rule.type property which was introduced in webpack 4.0:

javascript/auto: (The default one in webpack 3) Javascript module with all module systems enabled: CommonJS, AMD, ESM
javascript/esm handles ESM more strictly compared to javascript/auto:
Imported names need to exist on imported module
Dynamic modules (non-esm, i. e. CommonJs) can only imported via default import, everything else (including namespace import) emit errors
In .mjs modules are javascript/esm by default

In my understanding setting the value javascript/auto tells webpack that it allows for mjs files to be not ESM strict.

This is a kind of hack and curcumvents the issue. In a proper setup mjs should only be handled as esm modules and nothing else.
So instead of changing how webpack sees mjs file we might want to
revert the change that introduced this issue.

Pull Request Checklist

If you are a community contributor, copy and paste the PR template from Dendron Community PR Checklist and add it to the body of the pull request.

If you are a team member, copy and paste the template from Dendron Extended PR Checklist.

To copy the template, click on the Raw button on the gist to copy the plaintext version of the template to this PR.

@namjul namjul marked this pull request as ready for review November 10, 2022 14:33
@kevinslin
Copy link
Member

  1. is this breaking then nightly build then if plugin-views is failing?
  2. can we pin the dependency of swc-helpers to be compatible?

@namjul namjul force-pushed the chore/fix-dendron-plugin-views-build branch from b3f3892 to 6bdc46c Compare November 11, 2022 09:24
This aim of this commit is to fix the build task within `dendron-plugin-views` package which currently results into the following error:

```
/home/nam/code/dendronhq/dendron/node_modules/zod-validation-error/node_modules/@swc/helpers/src/index.mjs
Can't reexport the named export '__decorate' from non EcmaScript module (only default export is available)
```

The commit 419dec7 (PR: #3762) is responsible for this by adding a dependency
which conflicts with the webpack build in `dendron-plugin-views`. That
dependency uses withing its cjs build files `@swc/helpers` which
conflicts with the import type from webpack.

The solution is to use explicitly set [`Rule.type`](https://webpack.js.org/configuration/module/#ruletype) property which was introduced in [webpack 4.0](https://github.com/webpack/webpack/releases/tag/v4.0.0):

> javascript/auto: (The default one in webpack 3) Javascript module with all module systems enabled: CommonJS, AMD, ESM
> javascript/esm handles ESM more strictly compared to javascript/auto:
>  Imported names need to exist on imported module
>  Dynamic modules (non-esm, i. e. CommonJs) can only imported via default import, everything else (including namespace import) emit errors
> In .mjs modules are javascript/esm by default

In my understanding setting the value `javascript/auto` tells webpack that it allows for `mjs` files to be not ESM strict.

This is a kind of hack and curcumvents the issue. In a proper setup `mjs` should only be handled as esm modules and nothing else.
So instead of changing how webpack sees `mjs` file we might want to
revert the change that introduced this issue.

References

- webpack/webpack#16213 (comment)
Webpacks's treeshaking is negatively impacted by telling it to prefer
`main` field instead of `module`. `module` point to esm modules which
are what webpack needs to do its [treeshaking](https://webpack.js.org/guides/tree-shaking/).
@namjul namjul force-pushed the chore/fix-dendron-plugin-views-build branch from 7400603 to d4609a7 Compare November 11, 2022 10:06
Intead of changing ``dendron-plugin-views` webpack build config this
commits pins `zod-validation-error` to an older version within its
dependency to `@swc/helpers` does not conflict with webpack rules.
@namjul
Copy link
Contributor Author

namjul commented Nov 11, 2022

  1. is this breaking then nightly build then if plugin-views is failing?

Yes, I believe that should fail.

  1. can we pin the dependency of swc-helpers to be compatible?

Found a version which works 5e406cc

@namjul namjul merged commit 8488c96 into master Nov 11, 2022
@namjul namjul deleted the chore/fix-dendron-plugin-views-build branch November 11, 2022 11:47
@namjul namjul changed the title chore: fix dendron-plugin-views build chore(internal): fix dendron-plugin-views build Nov 11, 2022
kevinslin pushed a commit that referenced this pull request Jun 11, 2023
* chore: fix `dendron-plugin-views` build

This aim of this commit is to fix the build task within `dendron-plugin-views` package which currently results into the following error:

```
/home/nam/code/dendronhq/dendron/node_modules/zod-validation-error/node_modules/@swc/helpers/src/index.mjs
Can't reexport the named export '__decorate' from non EcmaScript module (only default export is available)
```

The commit 419dec7 (PR: #3762) is responsible for this by adding a dependency
which conflicts with the webpack build in `dendron-plugin-views`. That
dependency uses withing its cjs build files `@swc/helpers` which
conflicts with the import type from webpack.

The solution is to use explicitly set [`Rule.type`](https://webpack.js.org/configuration/module/#ruletype) property which was introduced in [webpack 4.0](https://github.com/webpack/webpack/releases/tag/v4.0.0):

> javascript/auto: (The default one in webpack 3) Javascript module with all module systems enabled: CommonJS, AMD, ESM
> javascript/esm handles ESM more strictly compared to javascript/auto:
>  Imported names need to exist on imported module
>  Dynamic modules (non-esm, i. e. CommonJs) can only imported via default import, everything else (including namespace import) emit errors
> In .mjs modules are javascript/esm by default

In my understanding setting the value `javascript/auto` tells webpack that it allows for `mjs` files to be not ESM strict.

This is a kind of hack and curcumvents the issue. In a proper setup `mjs` should only be handled as esm modules and nothing else.
So instead of changing how webpack sees `mjs` file we might want to
revert the change that introduced this issue.

References

- webpack/webpack#16213 (comment)

* chore(internal): setup `dendron-plugin-views` build to prefer `main` entry field

References

- webpack/webpack#6459 (comment)
- graphql/graphql-js#1272 (comment)
- apollographql/apollo-link-state#302 (comment)

* chore(internal): reverting to prevent increased bundle size

Webpacks's treeshaking is negatively impacted by telling it to prefer
`main` field instead of `module`. `module` point to esm modules which
are what webpack needs to do its [treeshaking](https://webpack.js.org/guides/tree-shaking/).

* chore(internal): pin version of `zod-validation-error`

Intead of changing ``dendron-plugin-views` webpack build config this
commits pins `zod-validation-error` to an older version within its
dependency to `@swc/helpers` does not conflict with webpack rules.
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.

4 participants