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

Does not work if dynamic import path is a template literal #1

Open
CxRes opened this issue Aug 22, 2021 · 0 comments
Open

Does not work if dynamic import path is a template literal #1

CxRes opened this issue Aug 22, 2021 · 0 comments

Comments

@CxRes
Copy link

CxRes commented Aug 22, 2021

If one has a dynamic import statement of the form:

import(`/path/to/${file}`, { assert: { type: 'json' } }) 

rollup crashes with error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.resolve (path.js:162:9)
    at getImportPath (file:///D:/dev/Proto/syntropize70c/packages/apis/resource/node_modules/.pnpm/[email protected][email protected]/node_modules/rollup-plugin-import-assert/dist/import-assert.js:25:44)
    at file:///D:/dev/Proto/syntropize70c/packages/apis/resource/node_modules/.pnpm/[email protected][email protected]/node_modules/rollup-plugin-import-assert/dist/import-assert.js:48:40
    at Array.forEach (<anonymous>)
    at Object.transform (file:///D:/dev/Proto/syntropize70c/packages/apis/resource/node_modules/.pnpm/[email protected][email protected]/node_modules/rollup-plugin-import-assert/dist/import-assert.js:47:35)
    at file:///D:/dev/Proto/syntropize70c/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:20117:25
    at runNextTicks (internal/process/task_queues.js:60:5)
    at processImmediate (internal/timers.js:437:9) {
  code: 'PLUGIN_ERROR',
  pluginCode: 'ERR_INVALID_ARG_TYPE',
  plugin: 'rollup-plugin-import-assert',
  hook: 'transform',
  id: 'D:\\dev\\Proto\\syntropize70c\\packages\\apis\\resource\\src\\schema\\fetch.js',
  watchFiles: [...]

Looking into the code, I find that the second argument to getImportPath() is node.source.value which assumes the path to be a value; whereas the template literal leads to a tree no value property. I believe fixing this should resolve the issue.. Actually, any dynamic statement should just be left alone (except for appropriate modification of variable names, if import path is an expression).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant