prettier / prettier-synchronized

Synchronous version of Prettier
MIT License
23 stars 7 forks source link

TypeError: path.isAbsolute is not a function #16

Closed dominikfryc closed 9 months ago

dominikfryc commented 10 months ago

I'm trying to use a synchronous version of prettier to format the source code snippets in Storybook:

// .storybook/preview.ts
import { format } from '@prettier/sync';

const preview: Preview = {
  parameters: {
    docs: {
      source: {
        transform: (input: string) => format(input)
      }
    }
  }
}

But I get this error:

TypeError: path.isAbsolute is not a function
    at toImportId (http://localhost:6006/node_modules/.cache/sb-vite/deps/@prettier_sync.js?v=9b0cb352:123:45)
    at createSynchronizedPrettier (http://localhost:6006/node_modules/.cache/sb-vite/deps/@prettier_sync.js?v=9b0cb352:135:24)
    at node_modules/.pnpm/@prettier+sync@0.3.0_prettier@3.1.0/node_modules/@prettier/sync/index.cjs (http://localhost:6006/node_modules/.cache/sb-vite/deps/@prettier_sync.js?v=9b0cb352:169:22)
    at __require2 (http://localhost:6006/node_modules/.cache/sb-vite/deps/chunk-WGAPYIUP.js?v=9b0cb352:19:50)
    at http://localhost:6006/node_modules/.cache/sb-vite/deps/@prettier_sync.js?v=9b0cb352:173:16

What am I doing wrong, or how am I supposed to use it correctly?

fisker commented 9 months ago

Are you using it in browser?

dominikfryc commented 9 months ago

Yes. Is it possible to run it in a browser? Or can I use some polyfill to make it work?

fisker commented 9 months ago

See https://github.com/prettier/prettier-synchronized/issues/15#issuecomment-1674230017

dominikfryc commented 9 months ago

Ah, okay, thanks for your answer.