简体   繁体   English

找不到模块“dotenv/types”

[英]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.

相关问题 PM2 集群模式 - 找不到模块 'dotenv/config' - PM2 Cluster Mode - Cannot find module 'dotenv/config' 找不到模块'@ types / mongodb' - Cannot find module '@types/mongodb' 找不到模块“sequelize/types” - Cannot find module 'sequelize/types' 每当我尝试通过 Heroku 运行我的服务器时,我都会收到“错误:找不到模块 'dotenv'” - Whenever I try to run my server via Heroku I get "Error: Cannot find module 'dotenv'" 将 node.js 应用程序部署到 heroku 时出错(找不到模块 dotenv 和 npm ERR!errno 1) - Error while deploying node.js application to heroku (cannot find module dotenv, and npm ERR! errno 1) 找不到模块“内部/实用程序/类型” - Cannot find module 'internal/util/types' 如何在谷歌云应用引擎中修复“找不到模块'dotenv'”? - how to fix "Can not find module 'dotenv'" in google cloud app engine? 即使安装了@types/node,Typescript 也找不到模块“fs” - Typescript Cannot find Module "fs" even though @types/node installed 在Windows 10中找不到模块'internal / util / types' - Cannot find module 'internal/util/types' in windows 10 重新安装节点后:“找不到模块'internal / util / types'” - After node reinstalled: “Cannot find module 'internal/util/types' ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM