Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_PACKAGE_PATH_NOT_EXPORTED when attempting to import #6

Closed
folklorelabs opened this issue Sep 6, 2024 · 16 comments
Closed

ERR_PACKAGE_PATH_NOT_EXPORTED when attempting to import #6

folklorelabs opened this issue Sep 6, 2024 · 16 comments

Comments

@folklorelabs
Copy link

Hi -- been trying to find a decent html prettifier and stumbled upon your lib. Unfortunately I'm not able to import due to a ERR_PACKAGE_PATH_NOT_EXPORTED error.

Some extra context:

  • I can't share the actual repo/code because it's for a client :(
  • Running Node v18.20.2 and npm v10.5.0
  • I see the exports prop inside of the lib's package.json after installing so it's an odd callout/error. Also no eslint errors (it's usually very good about this sort of thing).
  • I'm using typescript (tsx in particular) with the following tsconfig:
{
  "compilerOptions": {
    "lib": [
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "incremental": true,
  },
  "include": [
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules",
    "scripts"
  ]
}

@folklorelabs folklorelabs changed the title ERR_PACKAGE_PATH_NOT_EXPORTED when attempting to use with tsx ERR_PACKAGE_PATH_NOT_EXPORTED when attempting to import Sep 6, 2024
@j4w8n
Copy link
Owner

j4w8n commented Sep 6, 2024

So it's throwing when you try to do this: import { prettify } from 'htmlfy'?

Also, what OS are you using? And can you share any more of the error output?

@j4w8n
Copy link
Owner

j4w8n commented Sep 18, 2024

I'm closing this issue, due to no response after two weeks. I can open it back up if needed.

@j4w8n j4w8n closed this as completed Sep 18, 2024
@folklorelabs
Copy link
Author

folklorelabs commented Sep 27, 2024

Using OSX, and yes I tried a few variations, but started with import { prettify } from 'htmlfy'. Are you not able to reproduce locally with tsx?

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

I'll give it a try this weekend.

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

@folklorelabs I'm not familiar with React, Next (if you're using that?) and tsx, but I did my best using npx create-next-app@latest. Then copied your tsconfig. However, it yelled about Next's return html in layout.tsx, so I had to add "jsx": "preserve" to the tsconfig.

Aside from that, I'm using Node 20.10.0 and npm 10.2.5, but I had no errors for the import and prettify worked as expected.

I tried this on an Ubuntu machine with WSL.

@j4w8n j4w8n reopened this Sep 28, 2024
@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
import { prettify } from "htmlfy";
import React from "react";

console.log(prettify('<div><p>hello</p><p>world</p></div>'))

const geistSans = localFont({
  src: "./fonts/GeistVF.woff",
  variable: "--font-geist-sans",
  weight: "100 900",
});
const geistMono = localFont({
  src: "./fonts/GeistMonoVF.woff",
  variable: "--font-geist-mono",
  weight: "100 900",
});

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={`${geistSans.variable} ${geistMono.variable}`}>
        {children}
      </body>
    </html>
  );
}
{
  "compilerOptions": {
    "jsx": "preserve",
    "lib": [
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ]
  },
  "include": [
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "scripts"
  ]
}

@folklorelabs
Copy link
Author

Ah, I hate these library names haha. tsx is a popular standalone library for compiling typescript to be run as node scripts.
https://www.npmjs.com/package/tsx

I'm fairly certain this is the conflict/root of the problem.

For more app context:

  • This is a data service that executes node scripts via cron job
  • It supports a next js app, but does not contain any react or next code itself
  • It does however import data schema files (zod + ts type definitions) from the main app which is why the tsconfig is configured like that

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

So if I do something like this, where script.ts is importing prettify, it should show the issue? npx tsx ./script.ts

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

I was able to reproduce the issue.

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

@folklorelabs I was able to resolve by adding "type": "module" to my test package's package.json.

Do you have that field in yours?

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

Essentially, htmlfy is an ESM-only library.

@folklorelabs
Copy link
Author

folklorelabs commented Sep 28, 2024

Ah gotcha okay! I think I have another conflicting library preventing that from working, but I will give that a shot! Maybe I can set that and then resolve my other library issues. Thanks for looking into this!

@j4w8n
Copy link
Owner

j4w8n commented Sep 28, 2024

I actually just realized that I might just need one more line in my package.json and you should be good.

Try installing the latest version, 0.3.0

@folklorelabs
Copy link
Author

That works! 🙌

@j4w8n
Copy link
Owner

j4w8n commented Sep 30, 2024

Awesome. After all of that, I hope it meets your needs!

@j4w8n j4w8n closed this as completed Sep 30, 2024
@folklorelabs
Copy link
Author

Definitely! We have a pretty janky pipeline and I'm excited to clean up the markup as part of that. Thanks again for the help and the library :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants