umijs / babel-plugin-import

Modularly import plugin for babel.
3.15k stars 403 forks source link

babel-plugin-import does not import babel-plugin-proposal-class-properties #598

Open cengizcmataraci opened 2 years ago

cengizcmataraci commented 2 years ago

I have a problem with babel-plugin-import. I want to use react-pdf-to-image package in my React.js project, I want to transform pdf to jpg so I added this package in my project, after that I got this error, "Support for the experimental syntax 'classPrivateProperties' isn't currently enabled". I searched for the solution and the solution is adding inside babel config file this package. I use babel-plugin-import and after I add plugin-proposal-class-properties I still get error. There may be something I missed but I've been really trying to figure this out for hours.

.babelrc.js

const plugins = [
  [
    'babel-plugin-import',
    {
      libraryName: '@material-ui/core',
      // Use "'libraryDirectory': ''," if your bundler does not support ES modules
      libraryDirectory: 'esm',
      camel2DashComponentName: false,
    },
    'core',
  ],
  [
    'babel-plugin-import',
    {
      libraryName: '@material-ui/icons',
      // Use "'libraryDirectory': ''," if your bundler does not support ES modules
      libraryDirectory: 'esm',
      camel2DashComponentName: false,
    },
    'icons',
  ],
  [
    'babel-plugin-import',
    {
      libraryName: '@babel/plugin-proposal-class-properties',
      // Use "'libraryDirectory': ''," if your bundler does not support ES modules
      libraryDirectory: 'esm',
      camel2DashComponentName: false,
    },
    '@babel/plugin-proposal-class-properties',
  ],
];

module.exports = { plugins };

error

./node_modules/pdfjs-dist/build/pdf.js
SyntaxError: C:\Users\cengi\desktop\navlungo\webapp\node_modules\pdfjs-dist\build\pdf.js: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (3312:3):

  3310 |
  3311 | class WorkerTransport {
> 3312 |   #docStats = null;
       |   ^
  3313 |   #pageCache = new Map();
  3314 |   #pagePromises = new Map();
  3315 |   #metadataPromise = null;

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-class-properties (https://git.io/vb4yQ) to the 'plugins' section to enable parsing.  
Athelian commented 2 years ago

@cengizcmataraci Did you ever manage to solve this issue?

cengizcmataraci commented 2 years ago

@cengizcmataraci Did you ever manage to solve this issue?

Sorry I couldn't figure it out.

lianer3588 commented 2 years ago

Is this problem solved? I also encountered similar problems 😣