Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new export * as ns syntax #10460

Closed
OliverJAsh opened this issue Feb 27, 2020 · 16 comments · Fixed by #11117
Closed

Support new export * as ns syntax #10460

OliverJAsh opened this issue Feb 27, 2020 · 16 comments · Fixed by #11117

Comments

@OliverJAsh
Copy link

OliverJAsh commented Feb 27, 2020

Feature request

There is new export syntax: export * as ns (stage 4).

https://github.com/tc39/proposal-export-ns-from

export * as ns from './test';

Currently this will error:

ERROR in ./src/proxy.js 1:9
Module parse failed: Unexpected token (1:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export * as ns from './test';
 @ ./src/index.js 1:0-29 2:12-14

FWIW, TypeScript recently added support for this: https://devblogs.microsoft.com/typescript/announcing-typescript-3-8/#export-star-as-namespace-syntax

What is the expected behavior?

What is motivation or use case for adding/changing the behavior?

How should this be implemented in your opinion?

Are you willing to work on this yourself?
yes

@sokra
Copy link
Member

sokra commented Feb 27, 2020

Does acorn already support it?

@OliverJAsh
Copy link
Author

Sounds like it's implemented inside a plugin: acornjs/acorn#742 (comment)

https://github.com/acornjs/acorn-export-ns-from

@sokra
Copy link
Member

sokra commented Feb 28, 2020

acorn PR: acornjs/acorn#889

@guillaume86
Copy link

I have this issue with typescript/ts-loader, is it a webpack issue or a ts-loader issue?

@alexander-akait
Copy link
Member

@guillaume86 ts-loader

@sokra sokra added this to Important in webpack 5 Mar 21, 2020
@sokra sokra moved this from Important to Yes in webpack 5 Mar 21, 2020
@ooyyloo
Copy link

ooyyloo commented May 19, 2020

@guillaume86 ts-loader

It's not a ts-loader issue. It happens because webpack 4 haven't used the newest acornjs version.

@guillaume86
Copy link

@ooyyloo thanks I'll just for a webpack update then

@appzuka
Copy link

appzuka commented Jun 6, 2020

Is this the same issue as TypeStrong/ts-loader#1121?

If you use a module target lower than es2020 then typescript will transpile the new export * syntax down to a version webpack can understand.

@jun-sheaf
Copy link

jun-sheaf commented Jun 30, 2020

A current workaround is to use Babel and its @babel/plugin-proposal-export-namespace-from plugin. You can set is up like so for bare-minimum babel:

For dependencies,

npm i -D @babel/core babel-loader @babel/plugin-proposal-export-namespace-from

In your webpack.config.js,

...
{
    test: /\.tsx?$/,
    use: [{
         loader: "babel-loader", // This should be the last loader of course
         options: {
              plugins: ["@babel/plugin-proposal-export-namespace-from"]
         }
    }, ...other loaders]
}
...

@OnurGvnc
Copy link

OnurGvnc commented Jul 3, 2020

as a temporary solution;
https://github.com/OnurGvnc/acorn-with-stage3

package.json:

{
  ...
  "resolutions": {
    "acorn": "npm:acorn-with-stage3"
  },
  "dependencies": {

@jun-sheaf
Copy link

as a temporary solution;
https://github.com/OnurGvnc/acorn-with-stage3

package.json:

{
  ...
  "resolutions": {
    "acorn": "npm:acorn-with-stage3"
  },
  "dependencies": {

A lot of packages rely on acorn. This can potentially break them. It is advisable to build on top rather than directly patch.

@noinkling
Copy link

A lot of packages rely on acorn. This can potentially break them.

Scoping it to Webpack only would help:

"resolutions": {
  "webpack/acorn": "npm:acorn-with-stage3"
},

@alexander-akait alexander-akait removed this from Yes in webpack 5 Jul 15, 2020
@jun-sheaf
Copy link

Scoping it to Webpack only would help

This only works on yarn.

@OnurGvnc
Copy link

Scoping it to Webpack only would help

This only works on yarn.

https://www.npmjs.com/package/npm-force-resolutions

@jun-sheaf
Copy link

jun-sheaf commented Jul 21, 2020

https://www.npmjs.com/package/npm-force-resolutions

npm-force-resolutions doesn't support that behavior.

@TheColorRed
Copy link

@appzuka I had to also change module to a version less than es2020

{
  "compilerOptions": {
    "target": "es2015",
    "module": "es2015"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants