next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Swc coverage plugin breaking with app folder

Open gaetleba opened this issue 3 years ago • 1 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.13.2
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.0.3-canary.0
      eslint-config-next: 13.0.2
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Using the new app folder with the plugin swc-plugin-coverage-instrument breaks. I get the following error when trying to visit a simple index page:

error - (sc_server)\node_modules\next\dist\shared\lib\app-router-context.js (10:40) @ eval
error - TypeError: _react.default.createContext is not a function
    at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/shared/lib/app-router-context.js:297:77)
    at Object.(sc_server)/./node_modules/next/dist/shared/lib/app-router-context.js (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\app\page.js:920:1)
    at __webpack_require__ (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\webpack-runtime.js:33:42)
    at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/client/components/app-router.js:2314:61)
    at Object.(sc_server)/./node_modules/next/dist/client/components/app-router.js (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\app\page.js:197:1)
    at __webpack_require__ (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\webpack-runtime.js:33:42)
    at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fpage&appPaths=%2Fpage&pagePath=private-next-app-dir%2Fpage.tsx&appDir=C%3A%5CUsers%5CWarrows%5Cworkspace%5Crepronext%5Cswc-coverage%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=C%3A%5CUsers%5CWarrows%5Cworkspace%5Crepronext%5Cswc-coverage&isDev=true&tsconfigPath=tsconfig.json!:28:24)
    at Object.(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fpage&appPaths=%2Fpage&pagePath=private-next-app-dir%2Fpage.tsx&appDir=C%3A%5CUsers%5CWarrows%5Cworkspace%5Crepronext%5Cswc-coverage%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=C%3A%5CUsers%5CWarrows%5Cworkspace%5Crepronext%5Cswc-coverage&isDev=true&tsconfigPath=tsconfig.json! (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\app\page.js:99:1)
    at __webpack_require__ (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\webpack-runtime.js:33:42)
    at __webpack_exec__ (C:\Users\Warrows\workspace\repronext\swc-coverage\.next\server\app\page.js:974:39) {
  page: '/'
}
null

It's possible to avoid the problem by using babel (with babel-plugin-istanbul) instead of swc or by staying with old pages instead of the app folder.

Expected Behavior

The index page should load

Link to reproduction

https://github.com/gaetleba/swc-plugin-coverage-instrument-bug-reproduction

To Reproduce

Try to open the index page and you should get the error.

gaetleba avatar Nov 07 '22 12:11 gaetleba

https://github.com/kwonoj/swc-plugin-coverage-instrument/issues/183#issuecomment-1305880772

I did a quick try and looks like this is not a next.js upstream bug, more of a bug in the plugin. Probably, this issue can be closed.

kwonoj avatar Nov 07 '22 16:11 kwonoj

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Dec 08 '22 12:12 github-actions[bot]