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

fix: oauth2 not defined by exports #7993

Merged
merged 4 commits into from
Aug 10, 2022
Merged

Conversation

ted-marozzi
Copy link
Contributor

Webpack 5 generates an error when using the CopyWebpackPlugin to copy the oauth2 redirect page.

    new CopyWebpackPlugin({
      patterns: [{
        // Copy the Swagger OAuth2 redirect file to the project root;
        // that file handles the OAuth2 redirect after authenticating the end-user.
        from: require.resolve('swagger-ui/dist/oauth2-redirect.html'),
        to: './'
      }]
    })

Error

Failed to load '/app/src/docs/webpack.config.js' config
[webpack-cli] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/oauth2-redirect.html' is not defined by "exports" in /app/src/docs/node_modules/swagger-ui/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:731:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at Object.<anonymous> (/app/src/docs/webpack.config.js:43:23)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Description

Marking the file as allowed to be exported in package.json.

Motivation and Context

This change fixes webpack5 with oauth.

How Has This Been Tested?

I changed the package.json in my node modules and reran the build and it succedded.

root@5a8544c102c9:/app/src/docs# npm start

> swagger-ui-webpack-getting-started@0.0.1 start
> webpack-dev-server --open

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:8080/
<i> [webpack-dev-server] Content not from webpack is served from '/app/src/docs/public' directory
<i> [webpack-dev-middleware] wait until bundle finished: /
asset app.bundle.js 11.2 MiB [emitted] (name: app)
asset oauth2-redirect.html 2.63 KiB [emitted] [from: node_modules/swagger-ui/dist/oauth2-redirect.html] [copied]

Screenshots (if appropriate):

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • [] Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@ted-marozzi
Copy link
Contributor Author

ted-marozzi commented Apr 24, 2022

For others that hit this you can do this (dodgy?) workaround.

        {
          // Copy the Swagger OAuth2 redirect file to the project root;
          // that file handles the OAuth2 redirect after authenticating the end-user.
          from: path.join(__dirname, 'node_modules', 'swagger-ui', 'dist', 'oauth2-redirect.html'),
          to: './'
        },

For the maintainers, if we can decide on a solution I will happily update the web-pack-getting-started sample to use the latest dependencies.

@ted-marozzi ted-marozzi changed the title fix: oauth2 not defined by exports fix: oauth2 not defined by exports - ONE LINE CHANGE Apr 26, 2022
@tim-lai
Copy link
Contributor

tim-lai commented May 2, 2022

@ted-marozzi Thanks for the PR! I would prefer updating the samples/webpack-getting-started/webpack.config.js that you cited in the comments, rather than adding the oauth2-redirect.html directly to package.json. The reason is because it appears that most(?) consumers of SwaggerUI do not need a change to package.json, therefore we can limit the change to the sample configuration documentation.

@ted-marozzi
Copy link
Contributor Author

I think I wasn't clear, this change would need to be merged to update the sample, webpack 5 is incompatible with the sample until this is merged. When it is merged I can update the sample config to use webpack 5

@ted-marozzi ted-marozzi changed the title fix: oauth2 not defined by exports - ONE LINE CHANGE fix: oauth2 not defined by exports Aug 1, 2022
@tim-lai tim-lai merged commit a6e05e5 into swagger-api:master Aug 10, 2022
@tim-lai
Copy link
Contributor

tim-lai commented Aug 10, 2022

@ted-marozzi Ah, thanks for the clarification. PR is now merged! Thanks for the contribution!

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