反应:找不到模块:无法解析“react-html-parser" [英] React: Module not found: Can't resolve 'react-html-parser'

查看:34
本文介绍了反应:找不到模块:无法解析“react-html-parser"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 docker 容器客户端"中安装 react-html-parser:

docker-compose.yml客户/Dockerfile-dev节点模块/来源/组件/种子.jsx

并尝试在此处导入:

Seeds.jsx

import React, { Component } from 'react';导入 ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 }来自'react-html-parser';从 'axios' 导入 axios;

'axios''react' 都安装好了,但没有安装 'react-html-parser'.控制台记录我的错误:

index.js:1437 ./src/components/Seeds.jsx找不到模块:无法解析/usr/src/app/src/components"中的react-html-parser"

package.json

<代码>{"name": "客户",版本":0.1.0",私人":真的,依赖关系":{"axios": "^0.18.0",反应":^ 16.8.2","react-dom": "^16.8.2","react-router-dom": "^4.3.1",反应脚本":2.1.5","react-html-parser":"^2.0.2", # <---------NEW"spotify-web-api-js": "^0.22.1"},脚本":{开始":反应脚本开始","build": "react-scripts build","test": "反应脚本测试",弹出":反应脚本弹出"},eslintConfig":{扩展":反应应用程序"},浏览器列表":[">0.2%",没死",不是即 <= 11",不是 op_mini 全部"],开发依赖":{"酶": "^3.8.0",酶适配器反应 16":^1.7.1"}}

Dockerfile-dev

# 基础镜像发件人节点:11.6.0-alpine# 设置工作目录工作目录/usr/src/app# 将 `/usr/src/app/node_modules/.bin` 添加到 $PATH环境路径/usr/src/app/node_modules/.bin:$PATH# 安装和缓存应用程序依赖项复制 package.json/usr/src/app/package.json运行 npm install --silent运行 npm install react-scripts@2.1.2 -g --silent# 启动应用CMD ["npm", "开始"]

docker-compose.yml

 客户端:建造:上下文:./services/clientdockerfile: Dockerfile-dev卷:- './services/client:/usr/src/app'- '/usr/src/app/node_modules'端口:- 3000:3000环境:- NODE_ENV=开发- REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}依赖于取决于:- 网络

我在我的 node_modules 文件夹中找不到模块...

我在这里遗漏了什么?

<小时>

编辑:没有 --silent 的 npm 安装:

npm WARN 已弃用 fsevents@1.2.4:太旧了npm WARN 已弃用 core-js@2.6.4:core-js@<2.6.8 不再维护.请升级到 core-js@3 或至少升级到 core-js@2 的实际版本.npm WARN deprecated joi@11.4.0:根据 hapi 支持政策 (hapi.im/support),此版本已被弃用.请升级到最新版本以获得最佳功能、错误修复和安全补丁.如果您此时无法升级,可以为旧版本提供付费支持 (hapi.im/commercial).npm WARN deprecated circle-json@0.3.3:CircularJSON 仅在维护中,flatted 是它的后继者.npm WARN 已弃用 kleur@2.0.2:如果您更喜欢旧语法,请升级到 kleur@3 或迁移到ansi-colors".访问<https://github.com/lukeed/kleur/releases/tag/v3.0.0>用于迁移路径.npm WARN deprecated flatten@1.0.2:我很久以前写过这个模块;你应该用别的东西.npm WARN 已弃用 hoek@4.2.1:根据 hapi 支持政策 (hapi.im/support),此版本已弃用.请升级到最新版本以获得最佳功能、错误修复和安全补丁.如果您此时无法升级,可以为旧版本提供付费支持 (hapi.im/commercial).npm WARN deprecated topo@2.0.2:根据 hapi 支持政策 (hapi.im/support),此版本已被弃用.请升级到最新版本以获得最佳功能、错误修复和安全补丁.如果您此时无法升级,可以为旧版本提供付费支持 (hapi.im/commercial).npm WARN 已弃用 left-pad@1.3.0:使用 String.prototype.padStart()>core-js@2.6.9 postinstall/usr/src/app/node_modules/core-js>节点脚本/安装后 ||回声忽略"感谢您使用 core-js ( https://github.com/zloirock/core-js ) 来填充 JavaScript 标准库!该项目需要您的帮助!请考虑在 Open Collective 或 Patreon 上支持 core-js:>https://opencollective.com/core-js>https://www.patreon.com/zloirock另外,core-js的作者(https://github.com/zloirock)正在找一份好工作-)>core-js-pure@3.1.3 postinstall/usr/src/app/node_modules/core-js-pure>节点脚本/安装后 ||回声忽略"感谢您使用 core-js ( https://github.com/zloirock/core-js ) 来填充 JavaScript 标准库!该项目需要您的帮助!请考虑在 Open Collective 或 Patreon 上支持 core-js:>https://opencollective.com/core-js>https://www.patreon.com/zloirock另外,core-js的作者(https://github.com/zloirock)正在找一份好工作-)npm 通知创建了一个锁文件作为 package-lock.json.你应该提交这个文件.npm WARN ts-pnp@1.1.2 需要 typescript@* 的对等点,但没有安装.您必须自己安装对等依赖项.npm WARN 可选 SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:fsevents@1.2.4 不受支持的平台:想要 {"os":"darwin","arch":"any"}(当前:{"os":"linux","arch":"x64"})npm WARN 可选 SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/chokidar/node_modules/fsevents):npm WARN notsup 跳过可选依赖项:fsevents@1.2.9 不受支持的平台:想要 {"os":"darwin","arch":"any"}(当前:{"os":"linux","arch":"x64"})

解决方案

当你的 docker-compose.yml 文件说:

卷:- '/usr/src/app/node_modules'

您告诉 Docker 您的 node_modules 目录包含需要跨容器运行保持的关键数据.第一次启动容器时,它将从映像中填充,但由于该目录包含关键数据,Docker 永远不会再次更新它,即使您尝试 npm install 其他模块.>

对于近期的解决方法,docker-compose stop 就足够了;码头工人组成 rm;docker-compose up --build 你的容器.删除现有容器(及其匿名卷)很重要.

I am trying to install react-html-parser in my docker container 'client':

docker-compose.yml
client/
      Dockerfile-dev
      node_modules/
      src/   
         components/
                   Seeds.jsx

and try and import it here:

Seeds.jsx

import React, { Component } from 'react';
import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 }
from 'react-html-parser';
import axios from 'axios';

'axios' and 'react' are instaled allright, but not 'react-html-parser'. Console logs me the error:

index.js:1437 ./src/components/Seeds.jsx
Module not found: Can't resolve 'react-html-parser' in '/usr/src/app/src/components'

package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "react": "^16.8.2",
    "react-dom": "^16.8.2",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.5",
    "react-html-parser":"^2.0.2", # <---------NEW
    "spotify-web-api-js": "^0.22.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1"
  }
}

Dockerfile-dev

# base image
FROM node:11.6.0-alpine

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /usr/src/app/package.json

RUN npm install --silent
RUN npm install react-scripts@2.1.2 -g --silent

# start app
CMD ["npm", "start"]

docker-compose.yml

  client:
    build:
      context: ./services/client
      dockerfile: Dockerfile-dev
    volumes:
      - './services/client:/usr/src/app'
      - '/usr/src/app/node_modules'
    ports:
      - 3000:3000
    environment:
      - NODE_ENV=development
      - REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}
    depends_on:
      - web

I can'f find the module inside my node_modules folder...

what am I missing here?


EDIT: npm install without --silent:

npm WARN deprecated fsevents@1.2.4: Way too old
npm WARN deprecated core-js@2.6.4: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm WARN deprecated joi@11.4.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0> for migration path(s).
npm WARN deprecated flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
npm WARN deprecated hoek@4.2.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated topo@2.0.2: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()

> core-js@2.6.9 postinstall /usr/src/app/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.1.3 postinstall /usr/src/app/node_modules/core-js-pure
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN ts-pnp@1.1.2 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

解决方案

When your docker-compose.yml file says:

volumes:
  - '/usr/src/app/node_modules'

You're telling Docker your node_modules directory contains critical data that needs to be persisted across container runs. The first time you launch the container it will get populated from the image, but because that directory contains critical data, Docker will never ever update it again, even if you try to npm install additional modules.

For a near-term workaround, it's enough to docker-compose stop; docker-compose rm; docker-compose up --build your containers. Deleting the existing container (and its anonymous volume) is important.

这篇关于反应:找不到模块:无法解析“react-html-parser"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆