teelou teelou - 3 months ago 15
Node.js Question

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?

Answer

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';