nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

Build fails with `Unexpected character #` in `node-fetch-native`

Open jmsfilipe opened this issue 3 years ago • 10 comments

Versions

  • nuxt-edge: 2.16.0-27720022.54e852f
  • node: v16.17.0

Reproduction

Additional Details

Steps to reproduce

  • Use latest nuxt-edge version
  • nuxt.config.js with target: 'static' and ssr: true
  • Running nuxt build fails with
ERROR in ./node_modules/node-fetch-native/dist/index.cjs 69:2
Module parse failed: Unexpected character '#' (69:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|  */
| class BlobDataItem {
>   #path
|   #start
| 
 @ ./node_modules/node-fetch-native/lib/index.cjs 1:18-46
 @ ./.nuxt/server.js
 @ multi ./node_modules/@nuxt/components/lib/installComponents.js ./.nuxt/server.js

What is Expected?

  • Running nuxt build should be successful

What is actually happening?

  • Seems like the node-fetch-native dependency used to be just node-fetch
  • This new dependency includes private methods syntax and webpack/eslint don't know how to deal with that? Maybe it needs to be transpiled?

jmsfilipe avatar Oct 09 '22 18:10 jmsfilipe

I have the exact same issue with regular Nuxt v2 (without the nuxt-edge package), same config. I can't generate anymore.

Billybobbonnet avatar Feb 06 '23 08:02 Billybobbonnet

I'm running into the same problem. Though I'm not using target: 'static' and ssr: true.

Local dev and build commands work just fine, but I'm getting this error just at Vercel.

sanderjn avatar Feb 08 '23 11:02 sanderjn

This seems an issue with webpack's support for class properties in node-fetch-native. We likely need to configure this in Nuxt 2.

cc: @pi0

danielroe avatar Feb 08 '23 19:02 danielroe

Any workaround for now?

sanderjn avatar Feb 09 '23 08:02 sanderjn

Any workaround for now?

Pin your Nuxt version to "nuxt": "2.15.7"

Billybobbonnet avatar Feb 09 '23 08:02 Billybobbonnet

I cant solve this issue yet, Can anybody solve this error? I'm tried with babel

jbmarflo avatar Feb 11 '23 15:02 jbmarflo

You could also add a alias from node-fetch-native back to node-fetch when using v2.16.x:

// nuxt.config.js

  build: {
    extend(config) {
      config.resolve.alias['node-fetch-native'] = require.resolve('node-fetch')
    }
  }

pimlie avatar Feb 14 '23 10:02 pimlie

I was using D3 with my app and needed a standalone build to import the library. Can confirm setting build.standalone in my nuxt.config to false makes it so the server finally compiles, but I no longer can import d3.

I wonder if putting the dependencies in build.transpile will allow it to build instead for those who still really need external dependencies as we wait for a solution.

transpile docs

KevinBunn avatar Feb 15 '23 14:02 KevinBunn

Any workaround for now?

Pin your Nuxt version to "nuxt": "2.15.7"

Pinning to 2.15.8 seems to work for our team too.

prinzt avatar Feb 17 '23 14:02 prinzt

You could also add a alias from node-fetch-native back to node-fetch when using v2.16.x:

// nuxt.config.js

  build: {
    extend(config) {
      config.resolve.alias['node-fetch-native'] = require.resolve('node-fetch')
    }
  }

Worked for me for now.

sheggi avatar Feb 27 '23 16:02 sheggi

// nuxt.config.js

  build: {
    extend(config) {
      config.resolve.alias['node-fetch-native'] = require.resolve('node-fetch')
    }
  }

Solution did not work for me, any other recommendations?

Node: 16.16.0 Nuxt: 2.15.7

harshadsatra avatar Mar 06 '23 07:03 harshadsatra

Everything above and including 2.16.0 causes this in my case when combining with nuxt.config.js -> build: { standalone: true }. I initially added this because of some ESM problems (https://github.com/nuxt/nuxt/issues/9223) when importing openlayers (https://github.com/openlayers/openlayers).

Jones-S avatar Mar 14 '23 20:03 Jones-S

Is there a solution for that? Got the same problem when deploying on Vercel

vitalii-bulyzhyn avatar Mar 15 '23 20:03 vitalii-bulyzhyn

This should be resolved in the edge channel after tonight's nightly build, or in the next release.

Let me know if not and I'll reopen.

danielroe avatar Mar 17 '23 10:03 danielroe

@danielroe hi. I updated the latest version of nuxt 2.16.3, but i got this error: image

buglavecz avatar Mar 20 '23 12:03 buglavecz

@buglavecz Would you open a new issue with a reproduction? 🙏

Do you still have this error if you manually add node-fetch-native to your project dependencies?

danielroe avatar Mar 20 '23 12:03 danielroe

@danielroe yes. I got same error, when I added manually node-fetch-native to my project. I will make an issue from this. thanks.

buglavecz avatar Mar 20 '23 12:03 buglavecz

@danielroe resolved: https://github.com/nuxt/nuxt/issues/19820 😄

buglavecz avatar Mar 20 '23 12:03 buglavecz

@danielroe I updated to nuxt 2.16.3 with vercel and node 16.x

got the following error: image

@vitalii-bulyzhyn did u find a solution?

Update: It works on 2.16.2 with this solution:

// nuxt.config.js

  build: {
    extend(config) {
      config.resolve.alias['node-fetch-native'] = require.resolve('node-fetch')
    }
  }

simonmaass avatar Mar 23 '23 13:03 simonmaass

@simonmaass Would you open a new issue with a reproduction? 🙏 Does it work if you manually add node-fetch-native to your dependencies?

danielroe avatar Mar 23 '23 16:03 danielroe

I had the same problem with Vercel. Manually adding node-fetch-native to the dependencies fixed the problem for me. Also runs flawlessly with Node 18.

GelsDEV avatar Mar 24 '23 17:03 GelsDEV

I add node-fetch-native as normal package and it fix the issue

dommi10 avatar Apr 19 '23 13:04 dommi10

Adding node-fetch-native to my dependencies did not fix the problem for [email protected]

joao-conde avatar Sep 25 '23 16:09 joao-conde

Adding to the dependencies wouldn't probably make a difference (i advice to usually remove such pins and only renew lockfile).

node-fetch-native is bundled with a Syntax that is not supported by Webpack 4.

Would be nice if you can open a new issue in nuxt/bridge to followup any possible solution. (or @danielroe shall we move this to bridge directly?)

pi0 avatar Sep 26 '23 11:09 pi0