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

Add no-commonjs-exports-with-import rule #902

Closed

Conversation

lencioni
Copy link
Contributor

We want to start using Webpack to resolve imports instead of Babel. One
key difference is that Webpack will break the bundle if you use import
in the same file that module.exports is used, but it will appear to
build pretty alright. When this happens, webpack outputs a warning like:

WARNING in ./foo.js
4:12-13 "export 'default' (imported as 'bar') was not found in './bar'

And when the JS is run in the browser, an error like the following is
logged:

Uncaught TypeError: Cannot assign to read only property 'exports' of
object '#<Object>'

To make this safer to turn on, I am adding this
no-commonjs-exports-with-import rule which reports when it encounters an
import in the same file as a CommonJS module.exports or exports.*.

We want to start using Webpack to resolve imports instead of Babel. One
key difference is that Webpack will break the bundle if you use `import`
in the same file that `module.exports` is used, but it will appear to
build pretty alright. When this happens, webpack outputs a warning like:

```
WARNING in ./foo.js
4:12-13 "export 'default' (imported as 'bar') was not found in './bar'
```

And when the JS is run in the browser, an error like the following is
logged:

```
Uncaught TypeError: Cannot assign to read only property 'exports' of
object '#<Object>'
```

To make this safer to turn on, I am adding this
no-commonjs-exports-with-import rule which reports when it encounters an
`import` in the same file as a CommonJS `module.exports` or `exports.*`.
@ljharb
Copy link
Member

ljharb commented Jul 25, 2017

This might be a duplicate of #804.

@ljharb ljharb marked this as a duplicate of #804 Jul 25, 2017
@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.09%) to 95.879% when pulling d064150 on lencioni:no-common-js-exports-with-import into 40f5635 on benmosher:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 95.879% when pulling d064150 on lencioni:no-common-js-exports-with-import into 40f5635 on benmosher:master.

@ljharb
Copy link
Member

ljharb commented Jan 31, 2021

#804 is now merged.

@ljharb ljharb closed this Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants