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

Package exports { default } #3

Closed
ninofiliu opened this issue Jan 23, 2023 · 7 comments
Closed

Package exports { default } #3

ninofiliu opened this issue Jan 23, 2023 · 7 comments

Comments

@ninofiliu
Copy link

ninofiliu commented Jan 23, 2023

The type defs and the docs asks to do this in vite.config.ts:

import { defineConfig } from "vite";
import plainText from "vite-plugin-plain-text";

export default defineConfig({
  plugins: [
    plainText(/\.glsl$/),
  ],
});

but this is what works for me:

import { defineConfig } from "vite";
import plainText from "vite-plugin-plain-text";

export default defineConfig({
  plugins: [
    // @ts-ignore
    plainText.default(/\.glsl$/), // <--
  ],
});

There seems to be a minor issue in your transpilation/commonjs/build pipeline :)

@zheeeng
Copy link
Owner

zheeeng commented Jan 24, 2023

Could you provide a minimal reproduction repo? It works fine with my case.

@ninofiliu
Copy link
Author

https://github.com/ninofiliu/vite-plugin-plain-text-bug

pnpm run dev

expected behavior: launches vite + vite-plugin-plain-text

actual behavior: this output

> vite-plugin-plain-text-bug@0.0.0 dev /home/nino/c/vite-plugin-plain-text-bug
> vite

failed to load config from /home/nino/c/vite-plugin-plain-text-bug/vite.config.ts
error when starting dev server:
TypeError: plainText is not a function
    at file:///home/nino/c/vite-plugin-plain-text-bug/vite.config.ts.timestamp-1674556087799.mjs:5:13
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
 ELIFECYCLE  Command failed with exit code 1.

if that helps:

nino@dell~/c/vite-plugin-plain-text-bugmain$ uname -a
Linux dell 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
nino@dell~/c/vite-plugin-plain-text-bugmain$ node -v
v18.13.0
nino@dell~/c/vite-plugin-plain-text-bugmain$ npm -v
8.19.3
nino@dell~/c/vite-plugin-plain-text-bugmain$ pnpm -v
7.25.1

@zheeeng
Copy link
Owner

zheeeng commented Jan 31, 2023

@ninofiliu I found your package.json has the field "type": "module", it specifies that all module importing is treated as ESM.

@ninofiliu
Copy link
Author

as it should be? I don't really understand

anyway I found a workaround by not using this plugin entirely and natively using vite's ?raw

@zheeeng
Copy link
Owner

zheeeng commented Jan 31, 2023

I can declare the CJS exporting and ESM exporting for your issue. But you still have to handle the other CJS-only packages.

@zheeeng
Copy link
Owner

zheeeng commented Jan 31, 2023

The latest release v1.3.2 supported your usage.

@ninofiliu
Copy link
Author

It works indeed, awesome!

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