babel: [Bug]: Unable to use pako in create-react-app 5 with latest babel v7.20.x

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, …)

Input code

The file from pako is node_modules/pako/dist/pako.esm.mjs

const gen_bitlen = (s, desc) =>
//    hello_deflate_state *s;
//    tree_desc *desc;    /* the tree descriptor */
{
  const tree            = desc.dyn_tree;
  const max_code        = desc.max_code;
 

The error from a build is

$ yarn build
yarn run v1.22.18
$ react-scripts build
Creating an optimized production build...
Failed to compile.

Module parse failed: Unexpected token (255:129)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
|  *     not null.
|  */
> var gen_bitlen = function gen_bitlen(s, desc) /*    hello_deflate_state *s;*/ /*    tree_desc *desc;    /* the tree descriptor */*/{
|   var tree = desc.dyn_tree;
|   var max_code = desc.max_code;


Configuration file name

package.json

Configuration

I use a default version of installing create-react-app with yarn.lock in https://github.com/cmdcolin/pako_error_in_cra5

Can eject the cra config to see details

Current and expected behavior

This I believe is a fairly recently change, and I’m not certain it’s babel that does this type of conversion of comment formats. If this is not true I can redirect this issue elsewhere!

The code worked when my yarn.lock has e.g. ~7.19.x versions of babel packages, but started failing now at ~7.20.x. there are many babel packages so I’m not sure which but a diff between working and non-working is at this pastebin https://pastebin.com/xe3HSAgW

Environment

  • babel 7.20.x (failing) babel 7.19.x (working)
  • node 18.20
  • yarn 1.22.18
  • ubuntu 22.10
  • not a monorepo but testing in a create react app

reproducible repo here https://github.com/cmdcolin/pako_error_in_cra5

Possible solution

No response

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Same error with React JS.

#13 246.2 
#13 246.2 Module parse failed: Unexpected token (10116:106)
#13 246.2 File was processed with these loaders:
#13 246.2  * ./node_modules/babel-loader/lib/index.js
#13 246.2 You may need an additional loader to handle the result of these loaders.
#13 246.2 |  */
#13 246.2 | 
#13 246.2 > function gen_bitlen(s, desc) /*    deflate_state *s;*/ /*    tree_desc *desc;    /* the tree descriptor */*/{
#13 246.2 |   var tree = desc.dyn_tree;
#13 246.2 |   var max_code = desc.max_code;
#13 246.2 
#13 246.2 
#13 ERROR: executor failed running [/bin/sh -c npm run build]: runc did not terminate sucessfully

This is happening to me in angular as well. `./node_modules/pako/lib/zlib/trees.js:257:106 - Error: Module parse failed: Unexpected token (257:106) File was processed with these loaders:

  • ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
  • ./node_modules/@angular-devkit/build-angular/node_modules/@ngtools/webpack/src/ivy/index.js You may need an additional loader to handle the result of these loaders. | * not null. | */

function gen_bitlen(s, desc) /* deflate_state s;/ /* tree_desc desc; / the tree descriptor //{ | var tree = desc.dyn_tree; | var max_code = desc.max_code;`

@JLHwung Any eta on when the fix will be published?

I think https://github.com/cmdcolin/pako_error_in_cra5 is using 7.20.2 of @babel/core

can see in yarn.lock for details

and it does still produce the error. do you think this issue should re-open?