-
Notifications
You must be signed in to change notification settings - Fork 63
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
Error Unexpected token after import stimulus-autocomplete #92
Comments
@xama it seems there's a problem with your webpack configuration. What version of webpack are you using? |
I'm having the same issue and I'm on rails 5.2.6.2 with Webpack 4.44.2 |
same here. rails 7.0.3.1, shakapacker 6.5.0, webpack 5.73.0. |
i figured it out for me. setup:
i inspected the shakapacker-provided rule for js files by putting this in const { webpackConfig, merge } = require('shakapacker')
const jsRule = webpackConfig.module.rules.find(rule => rule.test.test('.js'));
const { exclude, include } = jsRule
console.log({exclude, include})
process.exit() which resulted in
i then fiddled around by adding then it appeared to me that const { webpackConfig, merge } = require('shakapacker')
const jsRule = webpackConfig.module.rules.find(rule => rule.test.test('.js'));
const transpilePackages = [ /stimulus-autocomplete/ ]
jsRule.include = [
...jsRule.include,
...transpilePackages
]
jsRule.exclude = {
and: [ jsRule.exclude ],
not: transpilePackages
} e voila. webpack transpiled the specified node packages (according to my babel/browserslist config). |
Using babel with webpacker and rails 6, we had code in the
I'd like to know though why this is necessary. Is it because there is not an es4-compatible minified version of the code provided in the package? If this is the case, why not? It seems odd that special configuration would be needed only for this package. I'm sure there are probably a few other packages out there that require this, but I've never encountered any until now. |
this package ships only modern js code (es6 if i'm not mistaken). most transpiler configurations exclude anything in node_modules because there is no way of knowing if a module actually needs transpiling or not. this assumption also reduces build times by a lot. so it's our job to configure.
i assume to reduce maintenance work and since everybody who needs older js output can run it through their transpiler...
you're gonna need this for other packages as well. i have a bunch of special cases that i use with my example config above. see the package
yes, there are. until recently, the world basically ran on es5 or sth even older. now, ie 11 is officially dead and we like to ditch old things so maintainers are moving forward. |
Hello,
I have this error once I import stimulus-autocomplete :
thank you for your help
The text was updated successfully, but these errors were encountered: