alangpierce / sucrase

Super-fast alternative to Babel for when you can target modern JS runtimes
https://sucrase.io
MIT License
5.66k stars 142 forks source link

Can't import the named export 'parse' from non EcmaScript module (only default export is available) #476

Open mytecor opened 4 years ago

mytecor commented 4 years ago

Sucrase does not work with webpack

import sucrase from 'sucrase'
Webpack config ```js let webpack = require('webpack') // CSS let MiniCssExtractPlugin = require('mini-css-extract-plugin') let autoprefixer = require('autoprefixer-stylus') // Config module.exports = { entry: './examples/app.js', resolve: { extensions: ['.js', '.styl'] }, module: { rules: [ { test: /\.styl$/, use: [ { loader: MiniCssExtractPlugin.loader, options: { hmr: true, reloadAll: true } }, { loader: 'css-loader', options: { modules: false } }, { loader: 'stylus-loader', options: { use: [autoprefixer()] } } ], }, { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], plugins: ['@babel/plugin-syntax-jsx', '@babel/plugin-transform-react-jsx'] } } } ], }, plugins: [ new MiniCssExtractPlugin({ filename: '[name].css', }), new webpack.ProvidePlugin({ ReactDOM: 'react-dom', React: 'react' }) ], devServer: { contentBase: './examples', historyApiFallback: true, inline: true, hot: true, port: 80 } } ```
peterpme commented 4 years ago

I'm also getting this issue with create-react-app

sekoyo commented 4 years ago

Similar issue, CRA doesn't support .mjs files. But regardless wondering why sucrase doesn't compile to something standard like ESM modules? I guess it's primary target is Node and not the browser 😞 Edit: it does but it's under the name .mjs and there is a commonjs version at .js. This seems to confuse compilers.

./node_modules/sucrase/dist/Options-gen-types.mjs
Can't import the named export 'array' from non EcmaScript module (only default export is available)
sekoyo commented 4 years ago

I made a fork which works for CRA, Gatsby etc - yarn add sucrase-browser

steveruizok commented 3 years ago

Thanks @DominicTobias!

velikayikci commented 2 years ago

https://github.com/reactioncommerce/reaction-component-library/issues/399#issuecomment-467860022