Skip to content

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

Description

@CxRes

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/rollup-plugin-import-assert@1.1.2_acorn-import-assertions@1.7.6/node_modules/rollup-plugin-import-assert/dist/import-assert.js:25:44)
    at file:///D:/dev/Proto/syntropize70c/packages/apis/resource/node_modules/.pnpm/rollup-plugin-import-assert@1.1.2_acorn-import-assertions@1.7.6/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/rollup-plugin-import-assert@1.1.2_acorn-import-assertions@1.7.6/node_modules/rollup-plugin-import-assert/dist/import-assert.js:47:35)
    at file:///D:/dev/Proto/syntropize70c/node_modules/.pnpm/rollup@2.56.2/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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions