Currently, I am in the process of developing a Next.js project with yarn's Plug'n'Play feature. In this project, I have created several pages and added various packages, including mathjs: '^10.3.0'
to assist me in parsing user input. TypeScript and eslint are being used simultaneously.
While everything runs smoothly when executing yarn dev
, encountering an issue arises when attempting to compile the project using yarn build
. The specific error received is as follows:
# yarn build
info - Checking validity of types
info - Creating an optimized production build
info - Compiled successfully
> Build error occurred
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'mathjs' imported from E:\Code\JavaScript\Web\next\yolcruz\.next\server\pages\calculator.js
Did you mean to import mathjs-npm-10.3.0-2f674e19b3-3fb3b66be9.zip/node_modules/mathjs/lib/cjs/index.js?
at new NodeError (node:internal/errors:371:5)
at packageResolve (node:internal/modules/esm/resolve:930:9)
at moduleResolve (node:internal/modules/esm/resolve:976:18)
at defaultResolve (node:internal/modules/esm/resolve:1078:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
at ESMLoader.import (node:internal/modules/esm/loader:332:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1042:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
at importModuleDynamically (node:vm:381:46) {
type: 'Error',
code: 'ERR_MODULE_NOT_FOUND'
}
info - Collecting page data .
My approach involves leveraging yarn's Plug'n'Play functionality, which means there is no node_modules
directory present, and other packages do not cause errors during development. Could someone provide guidance on resolving this issue? Is it attributable to the package itself or a consequence of using Plug'n'Play?
The contents of my package.json file are as shown below:
{
"name": "yolcruz",
"packageManager": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6bfa7b4a886f5e8f7e8f7">[email protected]</a>",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"eslint-plugin-react": "latest",
"mathjs": "^10.3.0",
"next": "^12.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",
},
"devDependencies": {
"@types/eslint": "^8",
"@types/node": "^17.0.18",
"@types/react": "^17",
"@types/react-dom": "^17",
"autoprefixer": "^10.4.2",
"eslint": "^8.9.0",
"eslint-config-next": "^12.1.0",
"typescript": "^4.5.5"
}
}
Additionally, the node version being utilized is 16.14.0