nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.07k stars 622 forks source link

Running Nuxt Content ESM in Serverless #875

Open robmellett opened 3 years ago

robmellett commented 3 years ago

Hey there,

I'm trying to deploy the next default Nuxt Content Theme Docs to AWS Serverless and hitting a roadblock with node.

Steps to reproduce

// `nuxt.config.js`
import theme from '@nuxt/content-theme-docs'

module.exports = theme({
  docs: {
    primaryColor: '#E24F55'
  },
  loading: { color: '#00CD81' },

  telemetry: false,

  build: {
    // You can extend webpack config here
    transpile: ['@nuxt/content-theme-docs'],
  },
})

When running serverless deploy, I'm seeing the following error.

Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
            Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
            More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless Nuxt Plugin: build nuxt

 Syntax Error --------------------------------------------

  /github/workspace/nuxt.config.js:1
  import theme from '@nuxt/content-theme-docs'
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
      at compileFunction (<anonymous>)
      at wrapSafe (internal/modules/cjs/loader.js:979:16)
      at Module._compile (internal/modules/cjs/loader.js:1027:27)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Module.require (internal/modules/cjs/loader.js:952:19)
      at require (internal/modules/cjs/helpers.js:88:18)
      at ServerlessNuxtPlugin.build (/github/workspace/node_modules/serverless-nuxt-plugin/src/index.js:69:22)
      at PluginManager.invoke (/github/workspace/node_modules/serverless/lib/classes/PluginManager.js:552:20)
      at async PluginManager.spawn (/github/workspace/node_modules/serverless/lib/classes/PluginManager.js:574:5)
      at async Object.before:deploy:deploy [as hook] (/github/workspace/node_modules/serverless/lib/plugins/deploy.js:49:11)
      at async PluginManager.invoke (/github/workspace/node_modules/serverless/lib/classes/PluginManager.js:552:9)
      at async PluginManager.run (/github/workspace/node_modules/serverless/lib/classes/PluginManager.js:598:7)
      at async Serverless.run (/github/workspace/node_modules/serverless/lib/Serverless.js:313:5)
      at async /usr/local/lib/node_modules/serverless/scripts/serverless.js:634:9

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              14.16.1
     Framework Version:         2.38.0 (local)
     Plugin Version:            4.5.3
     SDK Version:               4.2.2
     Components Version:        3.9.1

I thought it might be possible to fix it by using require() within node12/14 by doing the following:


// `nuxt.config.js`
const theme =  require('@nuxt/content-theme-docs')

module.exports = theme({
// ...
})

But then I'm presented with the following error instead:

 FATAL  theme is not a function                                                                                               08:34:48

  at nuxt.config.js:3:18
  at f (node_modules/jiti/dist/jiti.js:1:54601)
  at Object.loadNuxtConfig (node_modules/@nuxt/config/dist/config.js:1082:15)
  at loadNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:338:32)
  at NuxtCommand.getNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:463:26)
  at Object.run (node_modules/@nuxt/cli/dist/cli-build.js:90:30)
  at NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:413:22)

I was wondering if you had any ideas on how I might approach this error?

Any advice or suggestions would be much appreciated. I've put together a issue repo here. https://github.com/robmellett/nuxt-documentation-serverless

Version

"@nuxt/content-theme-docs": "0.10.1",
"nuxt": "^2.15.2",
ChristianMurphy commented 3 years ago

This may be related to https://github.com/nuxt/nuxt.js/issues/5011