-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Next.js project fails to build, Unexpected token : at dist/style.css #3854
Comments
Can confirm I experience this as well. App builds fine with Not sure if this is useful info, but: the solution from #1934 is helping, but in
...you will then find that Been surveying related issues, and what's interesting is that it appears this fix used to work in both Now that we know exactly what's causing it, I think all we need for a hacky workaround is to do some Webpack magic to exclude those imports. I expect to have this working within a day or two and will post my fix when I do. |
Have you tried using @zeit/next-css ? |
Hmm, 2 days of tweaking the Webpack config, and I'm still stumped. I've tried the following
5-8. Tried each of the above, but now with As best I can tell, regardless of what we do in the Webpack config is
This one is the only one that's made a difference. When I do this, I can at least get Only thing I've found that gets
@rakannimer Ah, just saw that @imyjimmy 's example wasn't using |
Have you tried starting from the next.js provided examples? Go to either Next and amplify can be made to behave with each other but it can be quite painful, mostly from Amplify's end. |
Yup, those examples which use only the Going forward we'll probably go ahead with Next 9, and just remove |
Okay, yeah, that's the same experience that I had. Sorry I didn't realize that those examples didn't use the react bindings. I ejected from aws-amplify-react, too, and it has been nice to get away from. There are still various issues but they can usually be resolved by making sure that everything runs on the client with |
I have the same issue. In my components rollup config, I marked assets as external so that the Components outputs two bundles, main (using require) and module (using es6 modules) in package.json. So if I inspect the components bundle, I see Similar to above, I only get the error for next build and not dev mode. It seems to be breaking on the |
@vivshaw will this effort be open sourced anywhere? |
Any updates on this? |
I'm curious about this too. Anyone got this working? |
As a temporary stopgap I published my own package, https://www.npmjs.com/package/aws-amplify-react-jz, which is a fork of aws-amplify-react minus the offending line, and it seems to work. It reflects their version |
@imyjimmy thanks for that. Using it as - hopefully - a temporary solution. |
Any update on this , Already spend couple of hours on this , The :root CSS pseudo-class matches the root element of a tree representing the document. In HTML, :root represents the element and is identical to the selector html, except that its specificity is higher. |
@sachinrajgire you have a couple options: either delete everything in edit: get rid of the line |
Thanks @imyjimmy |
To get past the const withCSS = require('@zeit/next-css')
global.navigator = () => null
if (typeof require !== 'undefined') {
require.extensions['.less'] = () => {}
require.extensions['.css'] = file => {}
}
module.exports = withCSS({
}); This will render the full Seems like in general there is an issue loading css from node_modules discussed here (this still fails on production build): And RFC for css support in next.js here: |
Updated const withCSS = require('@zeit/next-css')
const resolve = require('resolve')
global.navigator = () => null
module.exports = withCSS({
webpack (config, options) {
const { dir, isServer } = options
config.externals = []
if (isServer) {
config.externals.push((context, request, callback) => {
resolve(request, { basedir: dir, preserveSymlinks: true }, (err, res) => {
if (err) {
return callback()
}
if (
res.match(/node_modules[/\\].*\.css/)
&& !res.match(/node_modules[/\\]webpack/)
&& !res.match(/node_modules[/\\]@aws-amplify/)
) {
return callback(null, `commonjs ${request}`)
}
callback()
})
})
}
return config
}
}); |
@mlabieniec This works super well allowing me to remove all of the resolutions from my previous comment. Thanks a ton!!!! I am still experiencing build errors. However it is not related to navigator now. I don't believe this pertains to this issue though, I think this is a separate config issue that I am having with my project. |
I had the same issue using
|
OK here is my current next.config.js and everything is working ok
|
@mlabieniec Thanks for your solution. Unfortunately it doesn't work when using React hooks due to |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump |
@jskrt can you describe what's still broken for you? I've transitioned away from using AWS Amplify and haven't had time to look at this thread, but I think it's still relevant to lots of people. |
As quoted, hooks don't work with this solution. Has anybody found a solution that doesn't break hooks? Edit: the solution by @eastuto appears to be working. Edit2: wrote a gist that implements this solution more granularly and without using deprecated features of node.js. |
With the latest release of import '@aws-amplify/ui/dist/style.css'; Please open a new issue if your experience differs! |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Description
I have Next.js project and have added aws-amplify. During the build, I get the following error:
I have looked at the solution described in #1934 and my
next.config.js
has been set up accordingly:However, the build still fails.
To Reproduce
I will create a minimum github project that shows this issue. For now, clone my repo:I've created a minimum repo that shows this issue:
[email protected]:imyjimmy/nextjs-aws-amplify.git
Or, if you prefer to recreate from
npx
:npx create-next-app
url-loader
,css-loader
,style-loader
,postcss-loader
,autoprefixer
,aws-amplify
,aws-amplify-react
next.config.js
pages/index.js
yarn build
Expected behavior
I expect the build to complete.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: