cikatomo
cikatomo

Reputation: 1622

React import module working in development, but run build causes error

I have a script and exporting some functions from the script createPalette.js like this:

module.exports = { createPalette, generateFrameworkObject };

Then in React component Main.jsx I am importing the createPalette like this:

import { createPalette } from "../scripts/createPalette";

in development server it's working normally, but when trying to npm run build I get this error:

./src/components/Main.jsx
Attempted import error: 'createPalette' is not exported from '../scripts/createPalette'.


npm ERR! code ELIFECYCLE

How to fix this?

Upvotes: 0

Views: 388

Answers (1)

Elineo
Elineo

Reputation: 104

Can you replace

module.exports = { createPalette, generateFrameworkObject };

by

export { createPalette, generateFrameworkObject }

?

You are mixing es6 export/import with the old one.

Upvotes: 3

Related Questions