-
-
Notifications
You must be signed in to change notification settings - Fork 8k
import umd package from file system #5566
Copy link
Copy link
Closed
Labels
Description
Describe the bug
I have a problem with importing UMD packages coming from my filesystem and I don't understand the reason.
If I install an umd package from the package manager, I can import it without any issue into my project, but if I install the same package from the file system and try to import into my project, I receive a Uncaught SyntaxError: import not found: default exception.
Reproduction
for the exxample I take the UMD package chance because he has no dependencies.
npm init vite@latest
npm install
npm i chance// main.js
import chance from "chance";
console.log(chance);# ok
npm run build
# ok
npm run devI try the same but with chance from the file system.
cp -r node_modules/chance ../
npm rm chance
npm i ../chance# Error: 'default' is not exported by ../chance/chance.js
npm run build
# Uncaught SyntaxError: import not found: default
npm run devSystem Info
System:
OS: Linux 5.14 Arch Linux
CPU: (16) x64 Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz
Memory: 24.10 GB / 31.05 GB
Container: Yes
Shell: 5.1.8 - /bin/bash
Binaries:
Node: 16.7.0 - ~/.nvm/versions/node/v16.7.0/bin/node
npm: 7.20.6 - ~/.nvm/versions/node/v16.7.0/bin/npm
npmPackages:
vite: ^2.6.4 => 2.6.13Used Package Manager
npm
Logs
$ npm run build
> [email protected] build
> vite build --debug
vite v2.6.13 building for production...
✓ 4 modules transformed.
2021-11-05T23:31:54.971Z vite:config no config file found.
2021-11-05T23:31:54.977Z vite:config using resolved config: {
root: '~/sandbox/vite-project',
base: '/',
mode: 'production',
configFile: undefined,
logLevel: undefined,
clearScreen: undefined,
build: {
target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
polyfillModulePreload: true,
outDir: 'dist',
assetsDir: 'assets',
assetsInlineLimit: 4096,
cssCodeSplit: true,
cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
sourcemap: false,
rollupOptions: {},
minify: 'esbuild',
terserOptions: {},
write: true,
emptyOutDir: null,
manifest: false,
lib: false,
ssr: false,
ssrManifest: false,
reportCompressedSize: true,
chunkSizeWarningLimit: 500,
watch: null,
commonjsOptions: { include: [Array], extensions: [Array] },
dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
},
configFileDependencies: [],
inlineConfig: {
root: undefined,
base: undefined,
mode: undefined,
configFile: undefined,
logLevel: undefined,
clearScreen: undefined,
build: {}
},
resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
publicDir: '~/sandbox/vite-project/public',
cacheDir: '~/sandbox/vite-project/node_modules/.vite',
command: 'build',
isProduction: true,
plugins: [
'alias',
'vite:modulepreload-polyfill',
'vite:resolve',
'vite:html-inline-script-proxy',
'vite:css',
'vite:esbuild',
'vite:json',
'vite:wasm',
'vite:worker',
'vite:asset',
'vite:define',
'vite:css-post',
'vite:build-html',
'commonjs',
'vite:data-uri',
'rollup-plugin-dynamic-import-variables',
'vite:asset-import-meta-url',
'vite:build-import-analysis',
'vite:esbuild-transpile',
'vite:reporter',
'vite:load-fallback'
],
server: { fs: { strict: undefined, allow: [Array] } },
env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
assetsInclude: [Function: assetsInclude],
logger: {
hasWarned: false,
info: [Function: info],
warn: [Function: warn],
warnOnce: [Function: warnOnce],
error: [Function: error],
clearScreen: [Function: clearScreen],
hasErrorLogged: [Function: hasErrorLogged]
},
createResolver: [Function: createResolver],
optimizeDeps: {
esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
}
}
�[31m'default' is not exported by ../chance/chance.js, imported by main.js�[39m
file: �[36m~/sandbox/vite-project/main.js:13:7�[39m
�[33m11: // console.log(Map);�[39m
�[33m12: �[39m
�[33m13: import chance from "chance";�[39m
�[33m ^�[39m
�[33m14: console.log(chance);�[39m
�[31merror during build:�[39m
�[31mError: 'default' is not exported by ../chance/chance.js, imported by main.js�[39m
�[31m at error (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:158:30)�[39m
�[31m at Module.error (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:12382:16)�[39m
�[31m at Module.traceVariable (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:12767:29)�[39m
�[31m at ModuleScope.findVariable (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:11559:39)�[39m
�[31m at Identifier.bind (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:6419:40)�[39m
�[31m at CallExpression.bind (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:5021:31)�[39m
�[31m at CallExpression.bind (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:9396:15)�[39m
�[31m at ExpressionStatement.bind (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:5025:23)�[39m
�[31m at Program.bind (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:5021:31)�[39m
�[31m at Module.bindReferences (~/sandbox/vite-project/node_modules/rollup/dist/shared/rollup.js:12378:18)�[39mValidations
- Follow our Code of Conduct
- 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.
- 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.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable