Run
Run

Reputation: 57176

ES6 - Duplicate declaration on importing files

in pre-es6:

var stream = require("./models/stream");
var stream = require("./routes/stream");

It works fine.

In es6:

import stream from './models/stream';
import stream from './routes/stream';

Error:

TypeError: /var/www/.../es6/app.js: Duplicate declaration "stream"
> 31 | import stream from './routes/stream';

Any ideas how can I import it properly?

Upvotes: 0

Views: 2484

Answers (2)

Vedran Jukic
Vedran Jukic

Reputation: 851

Use different module names

import stream from './models/stream';
import streamroutes from './routes/stream';

Upvotes: 3

madox2
madox2

Reputation: 51851

You are re-declaring the stream variable and never use it, so you can just import first file without assignment:

import './models/stream';
import stream from './routes/stream';

Upvotes: 2

Related Questions