Skip to content
Advertisement

Build failed to compile – Attempted import error

My attempt to build for production fails every time because of this error:

Attempted import error: ‘decrypt’ is not exported from ‘../../../../util/security’ (imported as ‘decrypt’).

This error only appears when I try to build for production (npm run build).

Here is the way I import my modules:

JavaScript

And how I export it :

JavaScript

(The module decrypts my encrypted route)

I checked and the file is in the right place, moreover, in development mode it works as intended.

Advertisement

Answer

The solution here is to replace Node.js style exports (module.exports = ) with ES6 exports (export ... or export default ... depending on how you want to import it).

The reason is that import/export styles have to be compatible and while there are scenarios where this could work, mixing the two styles in a React app is not the best idea.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement