retextjs / retext-syntax-urls

plugin to classify url-like values as syntax, not natural language
https://unifiedjs.com
MIT License
9 stars 0 forks source link

Regression in 3.1.0 - TypeError: Cannot read property 'type' of undefined #2

Closed Zamiell closed 3 years ago

Zamiell commented 3 years ago

Initial checklist

Affected packages and versions

3.1.0

Link to runnable example

n/a

Steps to reproduce

git clone git@github.com:IsaacScript/isaacscript.github.io.git
cd isaacscript.github.io.git
git checkout c7acddaaf2aa66dcc593040384f2a269894c0b8f
vim .remarkrc.mjs

Comment out the line that says .use(retextSyntaxURLs) and save the file.

./lint.sh

Notice that it succeeds. Now, uncomment out the retextSyntaxURLs line.

./lint.sh

Notice that it fails with the following error:

docs\converting-lua-code.md
  1:1  error  TypeError: Cannot read property 'type' of undefined
    at mergeLinks (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/index.js:86:12)
    at Object.iteratee (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/unist-util-modify-children/index.js:48:12)
    at arrayIterate (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/array-iterate/index.js:37:25)
    at Array.iterator (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/unist-util-modify-children/index.js:37:5)
    at Of.run (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:46:23)
    at Of.Constructor.<computed> [as tokenizeSentence] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:17)
    at Of.parser (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/parser.js:13:43)
    at Of.Constructor.<computed> [as tokenizeParagraph] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:35)
    at Of.parser (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/parser.js:13:43)
    at Of.Constructor.<computed> [as tokenizeRoot] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:35)

Separately, you can confirm that this is a regression in this specific package by setting "retext-syntax-mentions": "3.0.0", in the package.json file, doing an npm install, and then running ./lint.sh, and observe that it succeeds (without commenting anything out).

Expected behavior

It should not produce any errors.

Actual behavior

It does produce an error.

Runtime

Node v16

Package manager

npm v7

OS

Windows

Build and bundle tools

Docusaurus

ChristianMurphy commented 3 years ago

@Zamiell what version of unified are you using? From this import https://github.com/IsaacScript/isaacscript.github.io/blob/d5e950662b343774e4fe1f2dca40e6acc44f06ec/.remarkrc.mjs#L5 it looks like Unified 9.X? (version 10 uses import {unified} from 'unified') The latest version of retext plugins, including retext-syntax-urls require unified 10.

Try running npm install unified or yarn add unified and see if that resolves the correct version of unified at the top level. (another library like docusaurus is likely including unified 9 as a transitive dependency, and that is causing an issue)

github-actions[bot] commented 3 years ago

Hi! Thanks for taking the time to contribute! This has been marked by a maintainer as needing more info. It’s not clear yet whether this is an issue. Here are a couple tips:

Thanks, — bb

Zamiell commented 3 years ago

what version of unified are you using?

I don't have any particular version of unified installed, as when I followed the tutorials for setting up retext, it was said to not be necessary. For reference, this is the package.json file from the repository that showcases the error: https://github.com/IsaacScript/isaacscript.github.io/blob/c7acddaaf2aa66dcc593040384f2a269894c0b8f/package.json

From this import https://github.com/IsaacScript/isaacscript.github.io/blob/d5e950662b343774e4fe1f2dca40e6acc44f06ec/.remarkrc.mjs#L5 it looks like Unified 9.X? (version 10 uses import {unified} from 'unified') The latest version of retext plugins, including retext-syntax-urls require unified 10. Try running npm install unified or yarn add unified and see if that resolves the correct version of unified at the top level. (another library like docusaurus is likely including unified 9 as a transitive dependency, and that is causing an issue)

Ok. I have:

1) Installed unified v10.1.0, the latest version, into my package.json.

2) Changed:

import unified from "unified";

to:

import { unified } from "unified";

However, after these two steps, I still get the exact same error:

docs\updating-isaacscript.md
  1:1  error  TypeError: Cannot read property 'type' of undefined
    at mergeLinks (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/index.js:86:12)
    at Object.iteratee (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/unist-util-modify-children/index.js:48:12)
    at arrayIterate (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/array-iterate/index.js:37:25)
    at Array.iterator (file:///D:/Repositories/isaacscript.github.io/node_modules/retext-syntax-urls/node_modules/unist-util-modify-children/index.js:37:5)
    at Of.run (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:46:23)
    at Of.Constructor.<computed> [as tokenizeSentence] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:17)
    at Of.parser (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/parser.js:13:43)
    at Of.Constructor.<computed> [as tokenizeParagraph] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:35)
    at Of.parser (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/parser.js:13:43)
    at Of.Constructor.<computed> [as tokenizeRoot] (file:///D:/Repositories/isaacscript.github.io/node_modules/parse-latin/lib/index.js:374:35)

× 9 errors

Please advise.

wooorm commented 3 years ago

Could you please try and make this reproduction a bit smaller? Try turning stuff off, removing stuff from your file — it’s a rather big repo, knowing what the input is that breaks would help a lot!

Zamiell commented 3 years ago

knowing what the input is that breaks would help a lot!

The input that makes the error appear is just any URL followed by a period.

For example, if you make a new file called test.md, and give it the following input:

[test1](https://www.test1.com/) test2.

It will trigger the error.

And the following input does not trigger the error:

[test1](https://www.test1.com/) test2
wooorm commented 3 years ago

I’m sorry, I can’t reproduce this problem:

Taking this code from the readme, with your fixture used instead:

import dictionary from 'dictionary-en-gb'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import retextEnglish from 'retext-english'
import retextSpell from 'retext-spell'
import retextSyntaxUrls from './index.js'
import retextStringify from 'retext-stringify'

unified()
  .use(retextEnglish)
  .use(retextSpell, dictionary)
  .use(retextStringify)
  .process('[test1](https://www.test1.com/) test2.')
  .then((file) => {
    console.log(reporter(file))
  })

And making sure all dependencies are installed (and up to date), then I don’t get any errors?

Zamiell commented 3 years ago

Hello woorm,

I've made a minimal repo for you. The steps to reproduce are as follows:

This repo only has one Markdown file in it, test.md, and a very simple .remarkrc.mjs config file.

wooorm commented 3 years ago

Thanks, that helped to narrow it down and find the bug! 👍