I have a React project that builds fine in my computer, but when I push it into my github repository, Netlify can't build it because of an import error. The thing is, I checked it many times, and it works on my computer, the import is correct. But for some reason I can't build it in Netlify.
Here is the build log:
6:11:53 PM: $ react-scripts build
6:11:55 PM: Creating an optimized production build...
6:12:19 PM: Failed to compile.
6:12:19 PM: ./src/views/Player.js
6:12:19 PM: Attempted import error: 'checkForPlayer' is not exported from '../Spotify'.
6:12:19 PM: error Command failed with exit code 1.
Here is my Player.js import
import { getState, checkForPlayer, transferPlaybackHere, getHashParams } from '../Spotify'
Here is my Spotify.js export
function checkForPlayer(authToken, player, setPlayer, playerRef, state, setState) {
if (window.Spotify !== null) {
const player = new window.Spotify.Player({
name: "Reactify",
getOAuthToken: cb => {
cb(authToken);
}
});
createEventHandlers(player, state, setState);
console.log("Conectado");
player.connect();
setPlayer(player);
playerRef.current = player;
} else {
setTimeout(checkForPlayer, 1000, authToken);
}
}
exports.checkForPlayer = checkForPlayer;
Does anyone know how can I fix this "bug"?
Just solved it by exporting each function with
export function checkForPlayer(authToken, player, setPlayer, playerRef, state, setState) { .... }
and removing
exports.checkForPlayer = checkForPlayer;