contentful / contentful-import

Node module that uses the data provided by contentful-export to import it to contentful space
MIT License
100 stars 39 forks source link

`Cannot open asset from filesystem` error when importing previously exported assets #819

Open BolajiAyodeji opened 1 year ago

BolajiAyodeji commented 1 year ago

Hi everyone (cc: @Khaledgarbaya).

I'm not sure if this is an unexpected behaviour from your end but I run into the error below when I try to import asset files that were previously exported using contentful-export:

    "error": {
      "filePath": "images.ctfassets.net/images.ctfassets.net/REDACTED/5bfbAxsoRLAGRBGmKhCJKp/0b0beedee30f8c52abaaa49c999210da/APRONXXX000000FFFFFFXXXX_FLAT.png",
      "stacktrace": [
        "Error: Cannot open asset from filesystem",
        "Object.getAssetStreamForURL (/Users/bolajiayodeji/REDACTED/node_modules/.pnpm/contentful-import@8.5.61/node_modules/contentful-import/dist/tasks/push-to-space/assets.js:22:19)",
        "async /Users/bolajiayodeji/REDACTED/node_modules/.pnpm/contentful-import@8.5.61/node_modules/contentful-import/dist/tasks/push-to-space/push-to-space.js:187:35",
        "async run (/Users/bolajiayodeji/REDACTED/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js:163:29)"
      ]
    }

When I ran the export command first, the library automatically exports the files to a /images.ctfassets.net/<space id>/<list of all children folders here>. Now in my import script, I use the /images.ctfassets.net base as the assetsDirectory but I kept running into the error above which shows you have added another images.ctfassets.net/ to the file path. Usually the files still gets imported which is weird but the publish process doesn't work (even though it shows green in the CLI). All assets files and even entries remain in draft mode and the import process returns all the errors before timing out:

The following 95 errors and 1 warnings occurred:

22:14:17 - Error: Cannot open asset from filesystem
22:14:17 - Error: Cannot open asset from filesystem
22:14:17 - Error: Cannot open asset from filesystem
22:14:17 - Error: Cannot open asset from filesystem
22:14:17 - Error: Cannot open asset from filesystem
...
...
22:14:30 - Error: Cannot open asset from filesystem
22:14:30 - Error: Cannot open asset from filesystem
22:16:51 - Connection error occurred. Waiting for 2091 ms before retrying...

A quick look at the assets import task show that you are joining the split file path with the passed accessDirectory which I presume is leading to the incorrect final file path. It's unclear how this process works with your library but something isn't working as expected.

Expected Behaviour

I expect that if I pass assetsDirectory: "./images.ctfassets.net" and run my script using the exact previously exported data, the import should succeed without any errors and all entires published. Am I missing anything here or is there something wrong with the library, please? Your docs doesn't explicitly explain what the accessDirectory path should look like so I'd assume there's no specific requirement here and a normal path used should work. It's quite frustrating to have to manually publish imported entires/image assets and force the multiple users that will use my import script to run into the same issue.

Thank you.

BolajiAyodeji commented 1 year ago

While I wait for further comments from anyone, I discovered that the exported JSON file with the assets lists all the assets from Contentful's CDN so you don't need to set uploadAssets: true and a file path since the import process will just import the assets. Doing this resolves my errors but this process is still unclear in the docs and developer experience. Ideally I'll expect a better error message to tell that you shouldn't use uploadAssets: true with and export file of CDN assets if this is the normal behaviour instead of proceeding.

Also the assets and all entries are still imported in draft mode even though the process is successful.