Skip to content

[PWA] Compile server - error Unexpected token in JSON at position 0 #492

@LivioAlvarenga

Description

@LivioAlvarenga

Summary

I am encountering an 'Unexpected token ` in JSON at position 0' error when trying to run my Next.js project with next-pwa. The issue only occurs when I attempt to use next-pwa; without it, my project runs as expected.

Versions

  • next-pwa: "5.6.0"
  • next: "13.4.7"

How To Reproduce

Steps to reproduce the behavior:

Create a new Next.js project or use an existing one.

Install dependencies: "next": "13.4.7" and "next-pwa": "5.6.0".

Add the following next.config.js:
`/** @type {import('next').NextConfig} */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const withPWA = require('next-pwa')({
dest: 'public',
register: true,
skipWaiting: true,
})

module.exports = withPWA({
reactStrictMode: true,
})
`

Run npm run dev.

See the error in the console:

`

[PWA] Compile client (static)
[PWA] Auto register service worker with: C:\project\node_modules\next-pwa\register.js
[PWA] Service worker: C:\project\public\sw.js
[PWA] url: /sw.js
[PWA] scope: /
[PWA] Build in develop mode, cache and
precache are mostly disabled. This means
offline support is disabled, but you can
continue developing other functions in service worker.
[PWA] Compile server
[PWA] Compile server

  • error Unexpected token ` in JSON at position 0
  • wait compiling...
  • error Unexpected token in JSON at position 0

Expected Behaviors

I expected the project to run smoothly with next-pwa enabled for PWA capabilities. However, I encounter an 'Unexpected token in JSON at position 0' error when runningnpm run dev`.

Additional Context

In this project, both server-side and client-side fetch requests are being made with caching enabled. The issue seems to persist regardless of these operations, but it's worth noting as it might be related to the problem at hand.

Minimum repository to reproduce the error

https://github.com/LivioAlvarenga/pwa-next

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions