prettier: Bug: Cr(...).__exportStar is not a function

Environments:

  • Prettier Version: 2.6.0
  • Running Prettier via: Node.js API, Browser API
  • Runtime: Node 16.14.0
  • Operating System: macOS

Context

Since 2.6.0, it seems Prettier can not be bundled with webpack, it throws this error Received: "Cr(...).__exportStar is not a function" (not at compile time but usage time). I saw there was a change to esbuild, might be that?

Steps to reproduce:

Hard to say at this point I’m just reporting as I found out.

import babel from 'prettier/parser-babel';
import prettier from 'prettier/standalone';

// Providing this plugin is required in order for prettier to use 'babel' as parser.
const prettierPlugins = [babel];

export function prettify(code: string): string {
  return prettier
    .format(code, { parser: 'babel', plugins: prettierPlugins })
    .trim();
}
  • webpack.config.js
const path = require('path');

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { ProvidePlugin } = require('webpack');

const resolvedExtensions = ['.js', '.jsx', '.ts', '.tsx'];

module.exports = function pack(env, options) {
  const mode = options.mode || 'development';
  const production = mode === 'production';

  // See what changes what here: https://webpack.js.org/configuration/devtool/#devtool
  let devtool = 'eval-cheap-module-source-map';
  if (production) {
    devtool = 'cheap-source-map';
  } else if (process.env.CI) {
    devtool = undefined;
  }

  return {
    target: 'web',
    mode,
    devtool,
    entry: {
      extractor: path.resolve(__dirname, 'src', 'extractor', 'index.ts'),
      converter: path.resolve(__dirname, 'src', 'converter', 'index.ts'),
    },
    output: {
      path: path.resolve(__dirname, 'build'),
      filename: '[name].js',
      libraryTarget: 'umd',
      library: 'exported',
      globalObject: 'this',
    },
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          exclude: /node_modules/,
          use: [
            {
              loader: 'babel-loader',
              options: {
                presets: [
                  [
                    '@babel/preset-env',
                    {
                      targets: {
                        browsers: ['last 2 versions'],
                      },
                    },
                  ],
                  [
                    '@babel/preset-typescript',
                    { isTSX: false, onlyRemoveTypeImports: true },
                  ],
                ],
                plugins: [
                  '@babel/plugin-proposal-object-rest-spread',
                  '@babel/plugin-proposal-class-properties',
                  '@babel/plugin-proposal-private-methods',
                  '@babel/plugin-proposal-private-property-in-object',
                  '@babel/plugin-proposal-optional-chaining',
                  '@babel/plugin-proposal-nullish-coalescing-operator',
                ],
                cacheDirectory: true,
                cacheCompression: false,
              },
            },
          ],
        },
      ],
    },
    resolve: {
      extensions: resolvedExtensions,
      modules: [path.resolve(__dirname, 'src'), 'node_modules'],
      fallback: {
        buffer: 'buffer',
        path: 'path-browserify',
        process: 'process/browser',
        url: 'core-js/stable/url',
        util: 'util',
        fs: false,
        tls: false,
        net: false,
        zlib: false,
        http: false,
        https: false,
        stream: false,
        crypto: false,
      },
    },
    plugins: [
      new CleanWebpackPlugin(),
      new ProvidePlugin({
        process: 'process/browser',
        Buffer: ['buffer', 'Buffer'],
        URL: 'core-js/stable/url',
      }),
    ],
    optimization: {
      minimize: production,
      minimizer: [
        new TerserPlugin({
          parallel: true,
          terserOptions: {
            /* eslint-disable camelcase */
            keep_classnames: true,
            keep_fnames: true,
            /* eslint-enable camelcase */
          },
        }),
      ],
    },
    stats: {
      assets: true,
      assetsSort: 'size',
      builtAt: false,
      cached: false,
      cachedAssets: false,
      children: false,
      chunks: false,
      colors: true,
      entrypoints: false,
      hash: false,
      loggingTrace: true,
      modules: false,
      version: false,
    },
    performance: {
      maxEntrypointSize: 920000,
      maxAssetSize: 920000,
    },
  };
};


**Expected behavior:**

**Actual behavior:**

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 32 (17 by maintainers)

Commits related to this issue

Most upvoted comments

@fisker I’ve upgraded to v2.6.1 and all works well - appreciate the quick work here! 👏

I believe #12511 should fix your problems.

To test it, replace your node_modules/prettier/standalone.js with this file https://deploy-preview-12511--prettier.netlify.app/lib/standalone.js

Welcome to feedback.

@fisker replacing standalone.js with the provided file (in https://github.com/prettier/prettier/issues/12493#issuecomment-1074718068) does fix the issue for me.

Okay, my release script has been rejected by diff between local and remote. But no problem. I’ll try to release again.

I start to release 2.6.1. /cc @fisker

@brianzinn I can’t help without details.

To test it, replace your node_modules/prettier/standalone.js with this file https://deploy-preview-12511--prettier.netlify.app/lib/standalone.js

@fisker that works for me 🎉

@alexander-akait Here’s the import syntax:

import prettier from 'prettier/standalone'

Is that what you wanted?