Code P0340 is no cam sensor signal.

Code p1391 is intermittant loss of cam or crank sensor signal.

The cam sensor is usually OK, what fails is the oil pump drive seizes and rotates in the block, and/or the drive gear breaks. The oil pump drive/Cam sensor is where the distributor would be on the older version of the 4.0l. If the sensor drive gear is broken, the cam should be inspected, as sometimes it breaks the distributor drive gear cut in the camshaft. If you install a new oil pump drive, it has to be "synced" to align it to top dead cylinder #1.

Another very common failure is the Crankshaft position sensor. It's mounted on top of the transmission bellhousing, on the driver's side, near the engine block. It's held in with one bolt and reads a tone wheel on the transmission flexplate. If you have access to a scan tool, check for RPM while cranking.

Without both sensor signals, you will get no spark or injector pulse.

Hope this helps!