iarna-toml icon indicating copy to clipboard operation
iarna-toml copied to clipboard

import toml using import statement in ts but failed

Open one0oneChen opened this issue 1 year ago • 2 comments

Hello, everyone. I tried to import toml using import statement in ts but failed, can someone help me

import toml from '@iarna/toml';
...
configdata = toml.parse(configstr)
hmr.ts:204  ReferenceError: global is not defined
    at node_modules/.pnpm/@[email protected]/node_modules/@iarna/toml/lib/create-date.js (create-date.js:3:18)
    at __require (chunk-Y2F7D3TJ.js?v=4804ad59:3:50)
    at node_modules/.pnpm/@[email protected]/node_modules/@iarna/toml/lib/toml-parser.js (toml-parser.js:26:20)
    at __require (chunk-Y2F7D3TJ.js?v=4804ad59:3:50)
    at node_modules/.pnpm/@[email protected]/node_modules/@iarna/toml/parse-string.js (parse-string.js:4:20)
    at __require (chunk-Y2F7D3TJ.js?v=4804ad59:3:50)
    at node_modules/.pnpm/@[email protected]/node_modules/@iarna/toml/parse.js (parse.js:2:18)
    at __require (chunk-Y2F7D3TJ.js?v=4804ad59:3:50)
    at node_modules/.pnpm/@[email protected]/node_modules/@iarna/toml/toml.js (toml.js:2:17)
    at __require (chunk-Y2F7D3TJ.js?v=4804ad59:3:50)
warnFailedUpdate @ hmr.ts:204
fetchUpdate @ hmr.ts:237
await in fetchUpdate(异步)
(anonymous) @ client.ts:182
handleMessage @ client.ts:180
(anonymous) @ client.ts:92
显示 5 更多框架
显示简略信息
hmr.ts:206  [hmr] Failed to reload /src/components/Index.vue. This could be due to syntax errors or importing non-existent modules. (see errors above)

one0oneChen avatar Jan 14 '24 14:01 one0oneChen

how about this: import * as toml from '@iarna/toml';?

khalilou88 avatar Jan 19 '24 14:01 khalilou88

@one0oneChen if you are using vite,global is not defined by default,you need to define it manually.you can see this post: https://stackoverflow.com/questions/72114775/vite-global-is-not-defined

SnowWarri0r avatar Mar 06 '24 03:03 SnowWarri0r