question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack cjs targetType compile jsPdf show error `Can't import the named export 'SVGPathData' (imported as 'SVGPathData') from default-exporting module (only default export is available)`

See original GitHub issue

Bug report

What is the current behavior? i use webpack5 to compile a vue2 component, which use jspdf.when i run webpack compile, it shows error… image

when i debug the code, i found that webpack resolve buildMeta of svg-pathdata which is used in jspdf dependence canvg, to default-only. but i look at the svg-pathdata code in github, svg-pathdata do not have a default export, it use rollup to compile the library…

If the current behavior is a bug, please provide the steps to reproduce. component code

import { jsPDF } from 'jspdf';
const pdfInstance = new jsPDF(image.width >= image.height ? 'landscape' : 'portrait', 'px', [image.width, image.height]);

webpack code

{
      name: 'cjs',
      target: 'web',
      context: path.join(ctxDir, entry.originalName),
      output: {
        path: path.join(ctxDir, entry.originalName, 'dist/cjs'),
        library: {
          type: 'commonjs2',
        },
      },
}

What is the expected behavior? it should resolve default-with-named when webpack resolve svg-pathdata

Other relevant information: webpack version: 5.68.0 Node.js version: v14.18.2 Operating System: mac Additional tools: vscode

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
vankopcommented, Feb 9, 2022

@wind4gis you should put $ in the end of regexp in your test option

test: /\.png|jpg|gif|jpeg|svg$/,

with this one should be ok

0reactions
wind4giscommented, Feb 9, 2022

i delete lerna and cli, you can checkout test branch, it’s a simple repo… and i found that maybe the image file loader rule cause the problem

{
        test: /\.png|jpg|gif|jpeg|svg/,
        type: 'asset',
        parser: {
          dataUrlCondition: {
            maxSize: 10 * 1024,
          },
        },
        generator: {
          filename: 'images/[base]',
        },
      },

when i run build comand it works ok, run build:svg it works wrong. you can checkout test branch, it’s so strange @vankop

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack - Error: Should not import the named export 'version ...
Error : Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon) ...
Read more >
should not import the named export 'domain ... - You.com
should not import the named export 'domain' (imported as 'domain') from default-exporting module (only default export is available soon).
Read more >
Can't import the named export from non EcmaScript module
Hi My site name is stupefied-lamarr-20c8d9 On the server side of my app I have lambda functions and within those I'm using apollo-server-lambda...
Read more >
jspdf - npm
Start using jspdf in your project by running `npm i jspdf`. There are 1012 other projects in the npm registry using jspdf.
Read more >
html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF. :warning: There have been several issues reported...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found