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

"You may need an appropriate loader?" error using next7 #7

Closed
KingScooty opened this issue Dec 3, 2018 · 11 comments
Closed

"You may need an appropriate loader?" error using next7 #7

KingScooty opened this issue Dec 3, 2018 · 11 comments

Comments

@KingScooty
Copy link

KingScooty commented Dec 3, 2018

So i'm not doing anything special. Have a few shared (via lerna/yarn workspaces monorepo structure) react components using styled components.

My babel.config.js file looks like this:

// babel.config.js (in your Next.js folder)
module.exports = api => {
	api.cache(true);

	const presets = ["next/babel"];

	const plugins = ["styled-components"];

	return {
		presets,
		plugins
	};
};

and my next.config.js file looks like:

const withTM = require("next-plugin-transpile-modules");
const withCSS = require("@zeit/next-css");
const withImages = require("next-images");

// Tell webpack to compile the "bar" package
// https://www.npmjs.com/package/next-plugin-transpile-modules
module.exports = withImages(
	withCSS(
		withTM({
			transpileModules: ["dh-ui-atom", "dh-ui-post"]
		})
	)
);

Running yarn dev in my next project runs, but when i try and load the page, i get the following error:

Module parse failed: Unexpected token (20:2)
You may need an appropriate loader to handle this file type.
| 	 */
| 	return (
> 		<div className={logoClasses}>

Weirdly, if i comment out the entries inside transpileModules, everything compiles fine, and the site loads, but then obviously none of the changes are being watched/hot reloaded, so it seems to be a local issue to transpile modules.

What am i doing wrong?

@martpie
Copy link
Owner

martpie commented Dec 4, 2018

Yarn is not supported because it copies dependencies instead of symlinking them. This is why hot-reloading is not working.

I will add a comment about that in the README because it is a common mistake.

Yarn workspaces work fine though.

I advice two things:

Tell me if it solves it for you :)

@martpie
Copy link
Owner

martpie commented Dec 4, 2018

I just added a FAQ to the README fyi.

@KingScooty
Copy link
Author

KingScooty commented Dec 4, 2018

I am actually already using yarn workspaces though! Just lerna for versioning. (i've updated my original comment).

I am using the latest canary version of next.

@martpie
Copy link
Owner

martpie commented Dec 4, 2018

@KingScooty
Copy link
Author

Yeah i've followed all the steps properly. I'm not sure what i've done wrong for a loader to be missing for JSX?

@martpie
Copy link
Owner

martpie commented Dec 5, 2018

You may need to adapt the babel.config.js to your needs though.

Can you provide an example/repo so I can reproduce your problem?

@KingScooty
Copy link
Author

It seemed to be an issue with one of the canary releases of next. I'm having to use canary releases due to the webpack upgrade that's included in them.

I can confirm this issue has gone away, but the hot reloading issue has come back. (next: ^7.0.2-canary.41)

@martpie
Copy link
Owner

martpie commented Dec 6, 2018

I’ll try to test this plugin with Canary to prevent a future incompatibility

@cyberwombat
Copy link

@martpie Can you elucidate:
"Yarn is not supported", "Yarn workspaces work fine though."

How would I use yarn workspaces without using yarn? I'm using yarn workspaces and cannot get next to transpile typescript using this module.

@martpie
Copy link
Owner

martpie commented Dec 6, 2020

This issue is 2 years old, please open a new one

@martpie
Copy link
Owner

martpie commented Dec 6, 2020

By "yarn is not supported", I meant yarn add ../../something is not supported ;)

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