Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem importing javascript files inside node_modules package folder #3840

Closed
6 tasks done
MagicCrazyMan opened this issue Jun 17, 2021 · 6 comments
Closed
6 tasks done

Comments

@MagicCrazyMan
Copy link

Describe the bug

I'm trying to migrate a cesium project from webpack to vitejs.
But error raised when i tried to directly import files inside the package folder. (which worked under webpack)

// error
import Cartesian3 from 'cesium/Source/Core/Cartesian3'

however, everything worked fine if i replaced the import statement to '/node_modules/cesium/Source/Core/Cartesian3',
while Vetur keep alerting me that Cannot find module '/node_modules/cesium/Source/Core/Cartesian3' or its corresponding type declarations.

// worked
import Cartesian3 from '/node_modules/cesium/Source/Core/Cartesian3'

i wanna a solution to fix this problem

Reproduction

  1. install cesium package
npm install cesium
  1. import cesium Source code in vitejs entry file
import Cartesian3 from 'cesium/Source/Core/Cartesian3'
  1. run dev server
npm run dev

and then the error may reported

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 3.05 GB / 11.90 GB
  Binaries:
    Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.48)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    @vitejs/plugin-vue: ^1.2.3 => 1.2.3
    vite: ^2.3.7 => 2.3.7

Used package manager:

Logs

error when starting dev server:
Error: Build failed with 1 error:
node_modules/vite/dist/node/chunks/dep-bc228bbb.js:32122:7: error: [plugin: vite:dep-scan] Missing "./Source/Core/Cartesian3" export in "cesium" package
    at failureErrorWithLog (<private_path>\test\node_modules\esbuild\lib\main.js:1449:15)
    at <private_path>\test\node_modules\esbuild\lib\main.js:1131:28
    at runOnEndCallbacks (<private_path>\test\node_modules\esbuild\lib\main.js:921:63)
    at buildResponseToResult (<private_path>\test\node_modules\esbuild\lib\main.js:1129:7)
    at <private_path>\test\node_modules\esbuild\lib\main.js:1236:14
    at <private_path>\test\node_modules\esbuild\lib\main.js:609:9
    at handleIncomingPacket (<private_path>\test\node_modules\esbuild\lib\main.js:706:9)
    at Socket.readFromStdout (<private_path>\test\node_modules\esbuild\lib\main.js:576:7)
    at Socket.emit (events.js:375:28)
    at addChunk (internal/streams/readable.js:290:12)

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
@javastation
Copy link
Contributor

Try this: import { Cartesian3 } from 'cesium'

@MagicCrazyMan
Copy link
Author

thanks for your reply!

i'd tried this, import { Cartesian3 } from 'cesium' worked fine also.
but there is still problem when i trying to import 'cesium/Source/Widgets/widgets.css' because i want to bundle the style sheet alongside.
i consider that they are the same problem

@javastation
Copy link
Contributor

Yes,they are the same problem, but css is not exposed to the outside, maybe vite should support this way of writing.

@MagicCrazyMan
Copy link
Author

i found a temporary solution, i replace cesium/ with /node_modules/cesium/ using resolve.alias in vite.config.js
it seems works fine

// vite.config.js
export default defineConfig({
  resolve: {
    alias: [
      {find: /^cesium\//, replacement: '/node_modules/cesium/'}
    ]
  },
  plugins: [vue()]
})

hoping vite may resolve this kind of problems
thanks for all your comments!

@MagicCrazyMan MagicCrazyMan changed the title Probleam importing javascript files inside node_modules package folder Problem importing javascript files inside node_modules package folder Jun 17, 2021
@haoqunjiang
Copy link
Member

I think it's an upstream issue. Tracked at CesiumGS/cesium#9212

@github-actions
Copy link

This issue has been locked since it has been closed for more than 14 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants