next-transpile-modules
Advanced tools
Comparing version 6.0.0 to 6.1.0
{ | ||
"name": "next-transpile-modules", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "author": "Pierre de la Martinière <pierre.de.la.martiniere@gmail.com>", | ||
"enhanced-resolve": "^5.3.2", | ||
"pkg-dir": "^5.0.0" | ||
"escalade": "^3.1.1" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
@@ -5,3 +5,5 @@ # Next.js + Transpile `node_modules` | ||
![Dependencies](https://img.shields.io/david/martpie/next-transpile-modules) | ||
[![sponsor: Creative Tim](https://img.shields.io/badge/sponsor-Creative%20Tim-blue)](https://creative-tim.com/?affiliate_id=140482) | ||
Transpile modules from `node_modules` using the Next.js Babel configuration. | ||
@@ -200,26 +202,12 @@ | ||
### I have trouble making it work with v5 | ||
### I have trouble making it work after upgrading to v5/v6 | ||
Please make sure to [read the changelog](https://github.com/martpie/next-transpile-modules/releases). | ||
### I have trouble making it work with Next.js 7 | ||
### I have trouble with transpilation and my custom `.babelrc` | ||
Next.js 7 introduced Webpack 4 and Babel 7, [which changed a couple of things](https://github.com/zeit/next.js/issues/5393#issuecomment-458517433), especially for TypeScript and Flow plugins. | ||
If you get a transpilation error when using a custom Babel configuration, make sure you are using a `babel.config.js` and not a `.babelrc`. | ||
If you have a transpilation error when loading a page, check that your `babel.config.js` is up to date and valid, [you may have forgotten a preset](https://github.com/martpie/next-transpile-modules/issues/1#issuecomment-427749256) there. | ||
The former is [a project-wide Babel configuration](https://babeljs.io/docs/en/config-files), when the latter works for relative paths only (and may not work for Yarn for example, as it installs dependencies in a parent directory). | ||
### I have trouble with transpilation and Flow/TypeScript | ||
In your Next.js app, make sure you use a `babel.config.js` and not a `.babelrc` as Babel's configuration file (see explanation below). | ||
**Since Next.js 9, you probably don't need that file anymore**, as TypeScript is supported natively. | ||
### I have trouble with transpilation and Yarn workspaces | ||
If you get a transpilation error when using Yarn workspaces, make sure you are using a `babel.config.js` and not a `.babelrc`. The former is [a project-wide Babel configuration](https://babeljs.io/docs/en/config-files), when the latter works for relative paths only (and won't work as Yarn install dependencies in a parent directory). | ||
### I have trouble with transpilation and my custom `.babelrc` | ||
Make sure you are using a `babel.config.js` and not a `.babelrc`. The former is [a project-wide Babel configuration](https://babeljs.io/docs/en/config-files), when the latter works for relative paths only. | ||
### I have trouble with Yarn and hot reloading | ||
@@ -233,3 +221,3 @@ | ||
Lerna's purpose is to publish different packages from a monorepo, **it does not help for and does not intend to help local development with local modules** (<- this, in caps). | ||
Lerna's purpose is to publish different packages from a monorepo, **it does not help for and does not intend to help local development with local modules** (<- this, **IN CAPS**). | ||
@@ -236,0 +224,0 @@ This is not coming from me, but [from Lerna's maintainer](https://github.com/lerna/lerna/issues/1243#issuecomment-401396850). |
@@ -5,3 +5,3 @@ const path = require('path'); | ||
const enhancedResolve = require('enhanced-resolve'); | ||
const pkgDir = require('pkg-dir'); | ||
const escalade = require('escalade/sync'); | ||
@@ -23,3 +23,3 @@ // Use me when needed | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.css', '.scss', '.sass'], | ||
mainFields: ['main', 'source'], | ||
mainFields: ['main', 'module', 'source'], | ||
}); | ||
@@ -63,6 +63,10 @@ | ||
try { | ||
// Get the location of its package.json | ||
packageRootDirectory = pkgDir.sync(packageDirectory); | ||
} catch (err) { | ||
// Get the location of its package.json | ||
const pkgPath = escalade(packageDirectory, (dir, names) => { | ||
if (names.includes('package.json')) { | ||
return 'package.json'; | ||
} | ||
return false; | ||
}); | ||
if (pkgPath == null) { | ||
throw new Error( | ||
@@ -72,2 +76,3 @@ `next-transpile-modules - an error happened when trying to get the root directory of "${module}". Is it missing a package.json?\n${err}` | ||
} | ||
packageRootDirectory = path.dirname(pkgPath); | ||
} catch (err) { | ||
@@ -102,3 +107,3 @@ throw new Error(`next-transpile-modules - an unexpected error happened when trying to resolve "${module}"\n${err}`); | ||
* @param {string[]} modules | ||
* @param {{resolveSymlinks?: boolean; debug?: boolean, unstable_webpack5?: boolean}} options | ||
* @param {{resolveSymlinks?: boolean, debug?: boolean, unstable_webpack5?: boolean}} options | ||
*/ | ||
@@ -123,8 +128,11 @@ const withTmInitializer = (modules = [], options = {}) => { | ||
// https://webpack.js.org/configuration/module/#ruleinclude | ||
const match = (path) => | ||
modulesPaths.some((modulePath) => { | ||
const transpiled = path.includes(modulePath); | ||
const match = (path) => { | ||
const lastEntry = path.split(`${path.sep}node_modules${path.sep}`).slice(-1)[0]; | ||
return modules.some((modulePath) => { | ||
const transpiled = lastEntry.includes(modulePath); | ||
if (transpiled) logger(`transpiled: ${path}`); | ||
return transpiled; | ||
}); | ||
}; | ||
@@ -131,0 +139,0 @@ return Object.assign({}, nextConfig, { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217
22460
277
+ Addedescalade@^3.1.1
+ Addedescalade@3.2.0(transitive)
- Removedpkg-dir@^5.0.0
- Removedfind-up@5.0.0(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpkg-dir@5.0.0(transitive)
- Removedyocto-queue@0.1.0(transitive)