codsen / codsen

a monorepo of npm packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to resolve path to module 'string-strip-html'

irfangg opened this issue · comments

Package's name
"string-strip-html": "^11.6.20",

using node version 16.12.0

Describe the bug
Getting SyntaxError: Cannot use import statement outside a module

4 | import { stripHtml } from 'string-strip-html';

To Reproduce

  1. yarn add string-strip-html
  2. import {stripHtml} from 'string-strip-html'
    image

Expected behavior
import { stripHtml } from 'string-strip-html'; should work

hi Irfan, I double-checked on a fresh new folder, (npm init -y then npm i string-strip-html) is does install ok. This program is pure-ESM, so that's a starting point for investigation.

  1. Familiarise with ESM first: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
  2. Prove the bug is unique to string-strip-html — try installing other popular pure-ESM packages such as matcher — see if they work
    2.1. if other pure-ESM packages don't work, it's definitely your app's configuration. It depends, what framework is it, google along the lines "create-react-app (or your framework) ESM packages install problem". It's possible your web application is bundling to CJS and not converting ESM dependencies and they "don't get along". Also, is there TypeScript involved?
    2.2. if other pure-ESM packages do work, create a minimal web app, similar to yours on stackblitz, for example, see this playground we've been troubleshooting things — without React context and your config it's impossible to recreate otherwise — maybe I can spot something
  3. if nothing works, try our last pre-ESM version, v8.3 — yarn add string-strip-html@8.3.0 (but some features can be missing there as it's from 2021 May)