teelou teelou -4 years ago 292
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';


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

Any ideas how can I import it properly?

Answer Source

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';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download