[英]Cannot find module 'dotenv/types'
Im using next.js and trying to set an environment variable - I have installed dotenv ofcourse by im being told that the module cannot be found and have no earthly idea as to why.我正在使用 next.js 并尝试设置一个环境变量 - 我已经安装了 dotenv 当然,我被告知无法找到该模块并且不知道为什么。 Why might something like this be happening?
为什么会发生这样的事情?
The dotenv is in my dependencies, But when i run dotenv --version i get told 'bash command not found' dotenv 在我的依赖项中,但是当我运行 dotenv --version 时,我被告知“找不到 bash 命令”
I should say that the below code is probably not relevant to the problem.我应该说下面的代码可能与问题无关。
in my .env file at the root of the doc i have在我的文档根目录下的 .env 文件中
API_URL = http://localhost:1337
Then in my config file i have然后在我的配置文件中我有
const path = require('path');
require('dotenv').config();
module.exports = {
env: {
API_URL: process.env.API_URL,
},
webpack: (config) => {
config.resolve.alias['components'] = path.join(_dirname, 'components');
config.resolve.alias['public'] = path.join(_dirname, 'public');
return config;
},
};
Im getting this on the the console:我在控制台上得到了这个:
Loaded env from C:\Users\sidtu\Documents\Websites\next-example\.env
Cannot find module 'dotenv/types'
code: 'MODULE_NOT_FOUND',
"The dotenv is in my dependencies, But when i run dotenv --version i get told 'bash command not found'" - That is typical behaviour for a npm package, only packages that are installed globally should be accessible from the command line. “dotenv 位于我的依赖项中,但是当我运行 dotenv --version 时,我被告知'找不到 bash 命令'” - 这是 npm 包的典型行为,只有全局安装的包才能从命令行访问。
If you are just using dotenv
in weback, use dotenv-webpack instead.如果你只是使用
dotenv
在weback,使用dotenv-的WebPack代替。
If you are having trouble getting .env
files to work with React see this blog如果您在使用 React 获取
.env
文件时遇到问题,请参阅此博客
Use npm to install dotenv-types使用npm安装 dotenv-types
$ npm i -g dotenv-types
Usage:用法:
$ dotenv-types -h
Source: https://www.npmjs.com/package/dotenv-types来源: https : //www.npmjs.com/package/dotenv-types
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.