Next.js: Re-exporting all exports from a page should be disallowed

Created on 8 Jun 2020  路  8Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Using export * from '...' in a page shouldn't be allowed by Next.js.

To Reproduce

Create two pages:

// pages/one.js
import fs from 'fs';

export default function A() {
  return <main />
}

export function getStaticProps() {
  fs;
  return { props: { } };
}
// pages/two.js
export * from './one'

This causes the following error:

Module not found: Can't resolve 'fs' in './pages/two.js'

Expected behavior

An build error should occur.

bug 2

All 8 comments

@Timer I came up with naive implementation regexing the page, but I'm quite sure there is a more "appropriate/elegant" way to achieve that. Maybe I should look into webpack?

@Timer I came up with naive implementation regexing the page, but I'm quite sure there is a more "appropriate/elegant" way to achieve that. Maybe I should look into webpack?

It can be achieved using a babel plugin

@Timer I came up with naive implementation regexing the page, but I'm quite sure there is a more "appropriate/elegant" way to achieve that. Maybe I should look into webpack?

It can be achieved using a babel plugin

I couldn't find any babel plugin for this issue. Does configuring .eslintrc will fix this issue?

It'll need to be a custom babel plugin!

@Timer or @timneutkens
In addition to export * from '...' in pages,
Does export {default} from '...' in pages too should be allowed or not ?

I got a custom babel plugin which works for export * from '...', work in progress :)

export {default} from '...'

is a fine behavior!

Hello, I would like to make my first contribution in the project, can I take this issue?

There's an open PR for this one already @AndresContreras96: #14325

Was this page helpful?
0 / 5 - 0 ratings