Nuxt.js: Cannot use import statement outside a module

Created on 12 May 2020  Â·  6Comments  Â·  Source: nuxt/nuxt.js

Version

v2.15.0

What is actually happening?

I want to import firebase in nuxt.config.js to get data from firestore for genereting dynamic route. but it show error :
SyntaxError: Cannot use import statement outside a module

Additional comments?

here is my code and error :
Screen Shot 2020-05-12 at 7.57.20 PM.png

this is for generating dynamic route:
Screen Shot 2020-05-12 at 7.55.21 PM.png

This bug report is available on Nuxt community (#c10647)
bug-report

All 6 comments

Please use export default instead of module.exports if you want to use the import statement.

@Atinux Sorry Sir. but it still does not work with me.
Screen Shot 2020-05-13 at 4 22 37 AM
i am importing firebase from plugins.
Screen Shot 2020-05-13 at 4 30 20 AM

I see you use server/index.js

So you need to use const { db } = require(‘../plugins/firebase’) and use module.exports

@Atinux after i use const { db } = require(‘../plugins/firebase’) and module.exports , it shows me this error. How can i fix this ,Sir?

Screen Shot 2020-05-13 at 5.19.35 AM.png

Has this issue been resolved? I have the same problem with VuePictureSwipe..

I just started seeing the same issue, but only when running with 'production' env in Azure App Service. It started after I switched from Linux to Windows App Service Plan. It works fine when running locally - both with nuxt-ts and nuxt-ts build & nuxt-ts start.

Version: nuxt: 2.13.0

After changing import statements to require, I'm getting the similar problem

const colors = require('vuetify/es5/util/colors')

// eslint-disable-next-line nuxt/no-cjs-in-config
module.exports = {
    //...config
nuxt-ts build


 FATAL  Cannot read property 'darken2' of undefined                                                                                                      12:30:41

  TypeError: Cannot read property 'darken2' of undefined
  at Object.<anonymous> (nuxt.config.js:125:32)
  at Generator.next (<anonymous>)

// EDIT
Alright, I'm getting the same error locally as I'm getting in Azure (SyntaxError: Cannot use import statement outside a module) if I start the application with node ./server/index.js.

I'm a little bit confused now - what's the preferred way to start an SSR application in Azure? Should I start it with nuxt-ts start or node ./server/index.js? Probably a dumb question, but can't see this being documented anywhere

// EDIT2
I solved the problem with vuetify colors with optionsPath option. However, now it's a different error - but not related to this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  Â·  3Comments

mattdharmon picture mattdharmon  Â·  3Comments

jaredreich picture jaredreich  Â·  3Comments

o-alexandrov picture o-alexandrov  Â·  3Comments

gary149 picture gary149  Â·  3Comments