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

Imports from /node_modules are not transpiled #1260

Closed
mgibas opened this issue Feb 9, 2018 · 4 comments
Closed

Imports from /node_modules are not transpiled #1260

mgibas opened this issue Feb 9, 2018 · 4 comments

Comments

@mgibas
Copy link

mgibas commented Feb 9, 2018

Just created new app using this commands:

rails new myapp --webpack
bundle
bundle exec rails webpacker:install

everything seems to be fine if it comes to /app/javascript/packs/application.js (code inside is transpiled the way I configure in .babelrc) but nothing happens to dependencies imported from /node_modules folder, ie.:

require('../../../node_modules/@mylib/mylib/file.js');

this will only output content of the file into a pack, but code is not picked up by babel :(

@mgibas
Copy link
Author

mgibas commented Feb 9, 2018

Seems like same thing as in #1239
Is this is by design and I can run into some weird issues ?

@renchap
Copy link
Contributor

renchap commented Feb 9, 2018

babel-loader ignores node_modules/ in the default config:

module.exports = {
test: /\.(js|jsx)?(\.erb)?$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
cacheDirectory: join(cache_path, 'babel-loader')

You can all an include option to make webpack process a specific module with Babel.

Ideally the exclude option should not be here, but some NPM packages are distributed with a .babelrc file, and running babel-loader on them will cause errors as Babel will try to use their specific .babelrc file, but you may not have the correct Babel plugins in your project. See babel/babel#6766 for some details on this.

@gauravtiwari
Copy link
Member

Thanks @renchap

Okay to close @mgibas ?

@mgibas
Copy link
Author

mgibas commented Feb 11, 2018

Yes, thanks @renchap and @gauravtiwari!

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

No branches or pull requests

3 participants