hashicorp / hashicorp/web-platform-packages

Cannot find module '.../generate-slug' imported from .../anchor-links/index.js

Open
#234 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
22
Forks
6
Avg merge
4d 6h
Merged PRs (30d)
4

Description

# Versions

- @hashicorp/platform-remark-plugins@0.2.0
- Node: v14.18.2

# Summary

I just tried upgrading from the older `@hashicorp/remark-plugins` to `@hashicorp/platform-remark-plugins`. I immediately get an error when trying to import `anchorLinks`:

```
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/mark/xxx/node_modules/@hashicorp/platform-remark-plugins/util/generate-slug' imported from /home/mark/xxx/node_modules/@hashicorp/platform-remark-plugins/plugins/anchor-links/index.js
at new NodeError (internal/errors.js:322:7)
at finalizeResolution (internal/modules/esm/resolve.js:308:11)
at moduleResolve (internal/modules/esm/resolve.js:731:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at ModuleWrap. (internal/modules/esm/module_job.js:76:40)
at link (internal/modules/esm/module_job.js:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
```

# Analysis

I believe the problem here is that the package has been migrated to ESM incompletely. Specifically, imports in an ESM project must include the file extension. This seems to have been done for most files, but `packages/remark-plugins/plugins/anchor-links/index.js` still has an import without a file extension. I believe line 1 of that file needs to change:

```diff
- import { generateSlug, generateAriaLabel } from '../../util/generate-slug'
+ import { generateSlug, generateAriaLabel } from '../../util/generate-slug.js'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.