uni-app Cannot find module 'uni-platform/helpers/get-real-path'
uni-app Cannot find module ‘uni-platform/helpers/get-real-path’
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 10 | CLI |
1.05.2108150 | ||
2.24.0 | ||
2.0.0-31920210709003 |
操作步骤:
- 使用cli编译,执行npm run build:mp-weixin
预期结果:
- 编译成功
实际结果:
- 报错Cannot find module ‘uni-platform/helpers/get-real-path’
bug描述:
- 使用npm run build:mp-weixin编译报错Cannot find module ‘uni-platform/helpers/get-real-path’
2 回复
已解决
The error message Cannot find module 'uni-platform/helpers/get-real-path'
in uni-app typically indicates that the specified module or file is missing or not correctly referenced in your project. Here are some steps to troubleshoot and resolve this issue:
1. Check the Module Path
- Ensure that the module
uni-platform/helpers/get-real-path
exists in your project. - Verify the correct path to the module. If it’s a custom module, make sure it’s placed in the correct directory and referenced properly.
2. Install Missing Dependencies
- If
uni-platform/helpers/get-real-path
is part of a third-party library or plugin, ensure that the library is installed in your project. - Run the following command to install dependencies:
npm install
- If the module is part of a specific package, install it explicitly:
npm install <package-name>
3. Check uni-app Version
- Ensure that your uni-app version is up to date. Some modules or helpers may only be available in newer versions.
- Update uni-app by running:
npm install @dcloudio/uni-app@latest
4. Verify uni-app Configuration
- Check your
manifest.json
orpages.json
for any misconfigurations that might affect module resolution. - Ensure that the
uni-platform
alias or path is correctly defined in your project configuration.
5. Rebuild the Project
- Sometimes, the issue can be resolved by cleaning and rebuilding the project.
- Delete the
node_modules
folder andpackage-lock.json
file, then reinstall dependencies:rm -rf node_modules package-lock.json npm install
- Rebuild the project:
npm run dev
6. Check for Typos
- Double-check the module name and path for any typos or incorrect casing. File paths are case-sensitive in most environments.
7. Custom Module
- If
get-real-path
is a custom module, ensure that it is correctly exported and imported in your project. - Example:
// get-real-path.js export default function getRealPath(path) { // Your logic here } // In your component or file import getRealPath from '@/helpers/get-real-path';