inkjs: Module parse failed

I get the following error when I try to use this package in a newly bootstrapped create-react-app application:

./node_modules/inkjs/dist/ink-es2015.js 491:14
Module parse failed: Identifier 'e' has already been declared (491:14)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|           let t = _ref4[0];
|           let e = _ref4[1];
>           let e = f.fromSerializedKey(t);
|           if (null === e.originName) return d("item.originName");
|

Out of the versions I tested, it happens in 1.9.* and 1.10.* but not in 1.7 or 1.8.

Steps to reproduce:

  1. make a project with create-react-app
  2. cd into that project and install inkjs
  3. modify App.js to import or require inkjs (don’t have to use it anywhere, just have to try and load it)
  4. npm start

I’ve only been playing around with create-react-app so I don’t know if it’s more general than that, but it does look like it might be an issue in any babel environment. Unfortunately I don’t know enough about babel to set an example up.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’m hitting this problem, I thought it was working @derekja but I think I was doing something silly.

I think I have found where the issue occurs in the ink build.

The terser plugin keeps the unused variable value in the for loop in inkjs-master/src/InkList.ts. Ln224 Col 24

for (let [key, value] of this) {
  let item = InkListItem.fromSerializedKey(key);
  if (item.originName === null) return throwNullException('item.originName');
  this._originNames.push(item.originName);
}

This gets output as in inkjs-es2015.js as: (formatted for clarity)

for(let[t,e]of this){
  let e=f.fromSerializedKey(t);
  if(null===e.originName) return d("item.originName");
  this._originNames.push(e.originName)
}

so webpack complains that Identifier 'e' has already been declared becauselet e=f.fromSerializedKey(t); is trying to overwrite the e value from the loop.

Since the e value in the loop is unused I’ve found that I can safely remove it from InkList.ts and rebuild. This prevents the issue.

I’ve tries various terser config options but I’m unable to get it to remove the unused variable e from the for loop.

@y-lohse I can make a PR if you want and you can take a look?

I’m fairly confident that version 1.11.0 doens’t have this problem anymore, so I’ll close this issue. Feel free to reopen it if you run into the same problem!

I’m hitting this problem as well, I’m afraid. I cannot yet reproduce in the sandbox. I will keep trying on a repro. The commonalities with OP include using create-react-app as a starting point. More soon…

I just released version 1.10.4, it solves the duplicate e declaration mentioned by @carlwells but it looks like there might be others in there. Wouldn’t mind a confirmation that the issue is still present though.

Cool! Note that you can probably do something like import Story from 'inkjs/dist/ink.js' without changing the dependency itself, though it depends how your bundler works. But glad you found a workaround 😃

Thanks @y-lohse ! The following workaround worked for me: I removed the es2015 version from the node module and changed the package.json of the module so that “main”: “dist/ink.js” (instead of the es2015 version)