This issue happens with the Webpack bundler v4 (it works just fine with metro) when resolving index.mjs. I believe the issue comes from incompatibilities between ESM and CommonJS modules. The index.mjs ESM cannot import non-ESM named exports.
So I guess replacing
import {
createElement
} from "react";
with
import React from "react";
const {
createElement
} = React;
would do the trick.
Workaround (expo)
Create / edit your webpack.config.js and add:
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
// Expo CLI will await this method so you can optionally return a promise.
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(env, argv);
// Allow named imports from CJS into ESM modules
config.module.rules.push({
type: 'javascript/auto',
test: /\.mjs$/,
use: []
});
return config;
};
To see this error in "action", check the package.json file of this snack and hover @mobility/stacks entry:
https://snack.expo.io/@jsamr/stacks-webpack-issue
This issue happens with the Webpack bundler v4 (it works just fine with metro) when resolving
index.mjs
. I believe the issue comes from incompatibilities between ESM and CommonJS modules. Theindex.mjs
ESM cannot import non-ESM named exports.So I guess replacing
with
would do the trick.
Workaround (expo)
Create / edit your
webpack.config.js
and add: