最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cannot find module 'immer' from 'node_modulesuse-immerdistuse-immer.js'? - Stack Ov

programmeradmin6浏览0评论

I use useImmer in react project. Locally, everything starts, but in Github Actions and when deploying in Vercel, an error occurs with Immer. As I understand it, it does not find the required module.

import React, { useState } from 'react';
import { useImmer } from 'use-immer';
import getModal from './modals/index';  

And the tests don't work because of the error.
GitHub Actions:

npm test -s
 FAIL  __tests__/test.jsx
  ● Test suite failed to run

    Cannot find module 'immer' from 'node_modules/use-immer/dist/use-immer.js'

    Require stack:
      node_modules/use-immer/dist/use-immer.js
      src/App.jsx
      __tests__/test.jsx

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:311:11)
      at Object.<anonymous> (node_modules/use-immer/dist/use-immer.js:1:94)

And the deployment does not work.
Vercel:

15:11:16.184    ERROR in ./node_modules/use-immer/dist/use-immer.module.js 1:0-21
15:11:16.184    Module not found: Error: Can't resolve 'immer' in '/vercel/path0/node_modules/use-immer/dist'

I use useImmer in react project. Locally, everything starts, but in Github Actions and when deploying in Vercel, an error occurs with Immer. As I understand it, it does not find the required module.

import React, { useState } from 'react';
import { useImmer } from 'use-immer';
import getModal from './modals/index';  

And the tests don't work because of the error.
GitHub Actions:

npm test -s
 FAIL  __tests__/test.jsx
  ● Test suite failed to run

    Cannot find module 'immer' from 'node_modules/use-immer/dist/use-immer.js'

    Require stack:
      node_modules/use-immer/dist/use-immer.js
      src/App.jsx
      __tests__/test.jsx

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:311:11)
      at Object.<anonymous> (node_modules/use-immer/dist/use-immer.js:1:94)

And the deployment does not work.
Vercel:

15:11:16.184    ERROR in ./node_modules/use-immer/dist/use-immer.module.js 1:0-21
15:11:16.184    Module not found: Error: Can't resolve 'immer' in '/vercel/path0/node_modules/use-immer/dist'
Share Improve this question edited Jun 22, 2021 at 16:50 Sergey Kirillov asked Jun 22, 2021 at 15:46 Sergey KirillovSergey Kirillov 6812 gold badges6 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Check whether immer is added as a dependency in your package.json. It's mentioned in peerDependencies of use-immer.

I just ran into this same issue, but solved it by installing immer as a seperate dependency. (i.e. yarn install immer use-immer). This also seems to be the solution on the official npmjs website: https://www.npmjs./package/use-immer.

发布评论

评论列表(0)

  1. 暂无评论