iamvishnusankar / next-sitemap

Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages.
https://next-sitemap.iamvishnusankar.com
MIT License
3.3k stars 127 forks source link

Unexpected token . (dot) (period) when running build #490

Closed adventurini closed 1 year ago

adventurini commented 2 years ago

Describe the bug Receiving an error after running npm run build from next-sitemap/dist/esm/cli.js:42

if (config?.generateRobotsTxt) {
 ^
Unexpected token '.'

To Reproduce

package.json:

{
  "name": "rg-landing",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "postbuild": "next-sitemap --config sitemap.config.js",
    "start": "next start",
    "lint": "next lint",
    "check-types": "tsc --pretty --noEmit",
    "check-format": "prettier --check .",
    "check-lint": "eslint . --ext ts --ext tsx --ext js",
    "format": "prettier --write .",
    "test-all": "npm run check-format && npm run check-lint && npm run check-types && npm run build",
    "prepare": "husky install",
    "analyze": "cross-env ANALYZE=true next build",
    "analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
    "analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"
  },
  "dependencies": {
    "@chakra-ui/icons": "^1.1.7",
    "@chakra-ui/pro-theme": "0.0.41",
    "@chakra-ui/react": "^1.8.6",
    "@emotion/react": "^11.8.2",
    "@emotion/styled": "^11.8.1",
    "@fontsource/montserrat": "^4.5.7",
    "@hubspot/api-client": "^6.0.1-beta5",
    "@next/bundle-analyzer": "^12.1.0",
    "aws-sdk": "^2.1206.0",
    "cross-env": "^7.0.3",
    "formik": "^2.2.9",
    "framer-motion": "^4.1.17",
    "i": "^0.3.7",
    "next": "12.1.0",
    "next-sitemap": "^3.1.22",
    "nextjs-google-analytics": "^2.1.0",
    "npm": "^8.6.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-icons": "^4.3.1",
    "react-slick": "^0.28.1",
    "slick-carousel": "^1.8.1",
    "winston": "^3.8.1",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@types/node": "17.0.21",
    "@types/react": "17.0.40",
    "@types/react-slick": "^0.23.8",
    "eslint": "8.10.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-next": "12.1.0",
    "eslint-config-prettier": "^8.5.0",
    "husky": "^7.0.0",
    "prettier": "2.5.1",
    "typescript": "4.6.2"
  }
}

sitemap.config.js ---> have tried several renditions (export default config, etc.)

/** @type {import('next-sitemap').IConfig} */
const config = {
  siteUrl: "https://riverguide.io",
  generateRobotsTxt: true,
  exclude: ["/sign-up"],
};

module.exports = { ...config };

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "declaration": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "pretty": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "es2018",
    "incremental": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "references/theme.ts",
    "fonts/**/*.d.ts"
  ],
  "exclude": ["node_modules"]
}

Expected behavior Build the sitemap.

stanleyivan96 commented 2 years ago

Was facing the same issue but resolved when I updated my node version from v12.22.7 to v14.18.1

sreetamdas commented 2 years ago

@adventurini could you mention the Node.js version you're using? You're using optional chaining which is only supported in Node.js v14+

The comment above also points to this 😄