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

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?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 23
  • Comments: 24 (5 by maintainers)

Most upvoted comments

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')
    }
  }

Any workaround for now?

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

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.

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.

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

Adding node-fetch-native to my dependencies did not fix the problem for nuxt@2.17.1

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.

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

// 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

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.

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.