Nuxt.js: Variable with name "module" throws error when imported in component

Created on 6 Apr 2019  路  2Comments  路  Source: nuxt/nuxt.js

Version

2.6.1

Reproduction link

https://codesandbox.io/s/zwvk4z2nl3

Steps to reproduce

  1. Create new nuxt application.
  2. Create test.js file in e.g. /store directory with export const module = {} line.
  3. Add import {module} from "~/store/test" line in pages/index.vue
  4. npm run dev and open application in browser.

What is expected ?

Page should be displayed without an error.

What is actually happening?

"Identifier 'module' has already been declared" error

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

Most helpful comment

It is not a bug. module is global object in node .
You can use module.exports = { variables } to export variables to another module .
So when you are using const to redefine the module, it will throw expection .

All 2 comments

It is not a bug. module is global object in node .
You can use module.exports = { variables } to export variables to another module .
So when you are using const to redefine the module, it will throw expection .

Ok, fair enough. That's a little strange however - between Nuxt versions 2.2 to 2.4 it worked flawlessly. Something changed in 2.5 or 2.6 that makes this node's "module" exposed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

msudgh picture msudgh  路  3Comments

vadimsg picture vadimsg  路  3Comments

vadimsg picture vadimsg  路  3Comments

mattdharmon picture mattdharmon  路  3Comments